Dependencies To Make Python Script Executable - python

I wrote a python program on Ubuntu(machine 1), working well.
I want to make it executable on machine 2(Fresh Ubuntu Installed) by using cxfreeze.
I run following commands on machine 2 terminal
sudo apt-get install python-pip
sudo pip install cxfreeze
cxfreeze pythonfile.py
After these command, when I try to run executable file, its Not working.
Not Working: means no error, no action and no message
It is my first experience, so want to know what steps I have to take before make it executable on different Ubuntu machine.

Related

General pip commands with Visual Studio

I'm currently trying to get my python project into an executable. I installed pyinstaller via the python environments on Visual studio:
and ran the command via this line:
Despite having found how to install packages using pip in this environment, I have not found how to actually run package commands. For example, I am trying to run the following pip command to generate an executable of my file:
pyinstaller --onefile --windowed database.py
Am I missing something here? Where do I do this?
(ps, I have git bash. Because I installed Python via Visual Studio, I cannot run pip or packages on my general bash shell)

Idlex 1.13 : Unable to located "idlexlib"

I really like IDLE because it's simple and intuitive, not to mention it is lightweight, but one turnoff is its lack of Line Numbers which is very important (for me).
I installed Python 3.6.0 for all users and then installed IdleX (python setup.py install), both as Admin. The setup went smoothly and the console displayed all processes just fine. However, when I tried to run idlex, an error showed:
Unable to located "idlexlib".
Make sure it is located in the same directory as "idlexlib" or run setup.py
to install IdleX.
python setup.py install --user
I tried uninstalling IDLE then installed it for single user, reboot then run again but the problem is still the same.
I tried upgrading to Python 3.6.1 but with no luck. I also tried copying LineNumbers.py to idlelib then edited configextensions.def but still no luck.
This should be a textbook setup (or so I thought) but I can't get it to work.
P.S.: Using Windows 10, 64-bit
Prerequisites
This solution works on Ubuntu 20.04.2 LTS,
using
python3
idle3
python3-setuptools
idlex-1.18.zip
The solution to the issue comes in the form of installing idlex, but there's more to it than that, so I've written the whole process.
Update Repo & Install dependencies
sudo apt update
sudo apt install -y idle3 python3-setuptools
Download IDLEx extension package
sudo wget http://sourceforge.net/projects/idlex/files/idlex-1.18.zip -P ~/
Unzip & make idlex hidden
cd ~/
unzip idlex-1.18
mv idlex-1.18 .idlex-1.18
Remove extra directories
rm -rf ~/idlex-1.18 ~/idlex-1.18.zip
Install idlex
cd ~/.idlex-1.18
sudo python3 setup.py install
Ensure Idlex runs
cd ~/.idlex-1.18
python3 idlex.py
Exit the program and proceed to next step.
Create Desktop Shortcut
Setup desktop shortcut for easy access
nano ~/Desktop/idlex.desktop
Paste into the text file:
python3 ~/.idlex-1.18/idlex.py
Press Ctrl+X and type "Y" and enter to save file to desktop.
Make idlex.desktop executable
In terminal, or
sudo chmod +x ~/Desktop/idlex.desktop
Through gnome
Right-click idlex.desktop on your desktop > select "Properties":
Go to Permissions tab
Check the box, "Allow executing file as program"

pyinstaller no predefined compiler for raspberry pi

I want to convert myscript.py to a exexutable file. i am using raspberry pi(raspbian) and python 2.7.
I am issuing the following command
sudo pip install PyInstaller
sudo pyinstaller myscript.py
after some processing it provides an error
Fatal error: PyInstaller does not include a pre-compiled bootloader for your
platform. See <http://pythonhosted.org/PyInstaller/#building-the-bootloader>
for more details and instructions how to build the bootloader.
i go online to build compiler but could not understand the process.
how could i solve this problem?
Full Tutorial
After many hours of searching, I got this working. The answer is straightforward, but it is spread across multiple StackExchange answers and GitHub Issues. I put it all together in this tutorial, so I save some hours for the next poor soul.
Key Takeaways
pip ships PyInstaller with the incorrect architectures. You need to build it yourself for ARM (Raspberry Pi).
Step by Step
1. Build the bootloader
git clone https://github.com/pyinstaller/pyinstaller
# Alternatively download the zip from https://github.com/pyinstaller/pyinstaller/releases
cd pyinstaller/bootloader
python ./waf distclean all # or python3
cd ../PyInstaller/bootloader/
ls
Here you should see Linux-32bit-arm and inside of it run and run_d
2. Check the bootloader
file Linux-32bit-arm/run
run: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=a01c65d74d7d8b483800154dcdd4a5d2aad95d5b, stripped
If you see the above, you are good so far. However, if you see something like ELF 32-bit LSB executable, Intel 80386, that is wrong.
3. Copy the bootloader
If you installed PyInstaller with pip inside a venv, then do this
# Replace ${CLONED_PYINSTALLER_PATH} with the path where you git cloned above
# Replace ${PATH_TO_YOUR_PROJECT} with the path to your project (where you have the venv)
cp -r ${CLONED_PYINSTALLER_PATH}/PyInstaller/bootloader/Linux-32bit-arm ${PATH_TO_YOUR_PROJECT}/venv/lib/python3.5/site-packages/PyInstaller/bootloader/
If you installed with apt-get, then do this
# !!! Replace python3.5 with your version
cp -r ${CLONED_PYINSTALLER_PATH}/PyInstaller/bootloader/Linux-32bit-arm /usr/local/lib/python3.5/dist-packages/PyInstaller/bootloader
Debugging
Issue
SystemError: objcopy Failure: objcopy: Unable to recognise the format of the input file `$FILE`
Check
`file dist/$FILE`
If it does not say ELF 32-bit LSB executable, ARM [...], but instead says Intel or x86, the PyInstaller tries to use the incorrect bootloader. If you executed all steps above, try renaming the Linux-32bit-arm to just Linux-32bit. That seems to have worked for this user
Issue
gcc not found
Solution
sudo apt-get install build-essential
Suspect path for the compilation of bootloader is wrong for your platform
may do this as mentioned in the forum here
cd /usr/local/lib/python2.7/dist-packages/PyInstaller/bootloader
sudo mv Linux-32bit Linux-32bit-arm
For RPI you need to get bootloader... You may cloned pyinstaller v3.1.1 into your rpi
Same thing, change the directory name for your arm platform after you have build the pyinstaller
cd /path/to/pyinstaller/PyInstaller/bootloader
cp -R Linux-32bit Linux-32bit-arm
For RPI, please clone the pyinstaller source code first and then follow my instructions.
Switch to pyinstaller/ bootloader subfolder.
Make the bootloader for your OS using the following command:
python3.5 ./waf distclean all
Make the Linux-32bit-arm sub-folder in /usr/local/lib/python3.5/dist-package/PyInstaller/bootloader
Copy the run and run_d to Linux-32bit-arm:
cp pyinstaller/bootloader/build/debug/run_d /usr/local/lib/python3.5/dist-package/PyInstaller/bootloader/Linux-32bit-arm/
cp pyinstaller/bootloader/build/release/run /usr/local/lib/python3.5/dist-package/PyInstaller/bootloader/Linux-32bit-arm/
I was able to install and create executables, on a Raspberry Pi running Raspbian (stretch 9.4), by running setup.py. Python version installed is 3.5.3.
git clone https://github.com/pyinstaller/pyinstaller
Inside pyinstaller source folder, run sudo python3 setup.py install
After, just execute pyinstaller <source>.py.

Running and installing missing modules for script through SSH

I want to run a python script on a Linux Box(I'm connecting to it through SSH on OSX terminal). In order for this script to run, the computer must have the SUDS module installed. I was wondering what would be the best way to install SUDS on computers that run my script and do not have SUDS installed in them. My script is in a folder the has a virtual env. The structure of my folder is:
MainFolder
-------script.py, env folder
|----------binFolder, includeFolder, libFolder
Should I code my script to install SUDS from the script itself?Or is there a better method to achieve this?
Also, I would like to know if there's a way to run my virtualenv through the SSH and use pip to install in the Linux Box?
Well it depends if you are deploying it only on this server and do not want to distribute the code than you would have to run the following command (assuming you have pip and python-tools)
sudo pip install SUDS
but if you get an error back saying that the command pip is not installed you will need to run the following command
sudo apt-get install python-pip python-dev build-essential
If you want to distribute it than I would do open source on github
with the instructions of how to use the program and run it I would add a dependencies list of all the external modules you used for your script.
Hope this helped.

How to install Pip on compiled from source Python

I'm on a raspberry pi running the latest Debian. It comes with 2.7.3 by default but I bought it to run a large Flask home automation app which was all written on 2.7.9 and I want no problems later on ( I know it is a minor version but I am a perfectionist).
So I downloaded the latest Python 2.7.10. And did
./configure && make && make altinstall
So far so good. It has installed the interpreter under /usr/local/bin as I expected. Now I need to to be able to run pip install -r requirements.txt, then I need pip. So I downloaded the get-pip.py from the Python website and tried
/usr/local/bin/Python2.7 get-pip.py
With no luck. I have also tried to create a virtualenv with a different my compiled Python interpreter like
virtualenv -p /usr/local/Python2.7 venv
No luck either. I was able to install easy_install on my compiled Python but it also throws me an error when I try
/usr/local/bin/easy_install pip
What am I doing wrong? I have read about --ensurepip flag for configuring Python at the first place, but Do I need to remove Python and install it all over again just to have pip on my compiled interpreter?
I was facing the same issue. I resolved it by appending an extra parameter to the configure command --with-ensurepip=install followed by make and make install. Then, my installation folder for python has pip there in.

Categories