I am using Ubuntu 18.04 in my work computer. I have never used Python2 versions before and it was annoying me to have in my computer because whenever I try to install something related Python I got issue even my default version Python3.6
I could not install pip, I could not install some packages so I wanted to delete Python completely from my computer. However now I can not install any python and getting lots of errors while trying several methods which are shared before on this platform and other websites.
Currently my terminal does not work so I use Xterm.
python --version
bash /usr/lib/command-not-found: /usr/bin/python3: bad interpreter: No such file or directory
whereis python
python: /usr/lib/python2.7 /usr/local/lib/python2.7 /usr/share/python /usr/share/man/man1/python.1.gz
sudo apt install python-minimal
sudo apt --fix-broken install
sudo apt update
I have tried many things I have seen on the web but could not fix. Also I am user in this computer so I do not have root access. Just wanted to know how to fix.
On Ubuntu 18.04 LTS I have the standard Python 2.7 and Python 3.6. My default python pointed to Python 2. I then installed virtualenv:
$ sudo pip install virtualenv virtualenvwrapper
$ sudo rm -rf ~/get-pip.py ~/.cache/pip
And modified my .bashrc by adding these lines:
export WORKON_HOME=~/Envs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh
Everything was fine and I could make virtual environments, install packages, work in them, deactivate them, etc.
Then one day I decided to upgrade my Python 3 to Python 3.7 because I needed to use asyncio. I followed this guide.
I made the new Python 3 my default and all seemed fine until I tried to open a new terminal. I got a message about virtualenv not being installed and then got the command prompt. But it was dead - I could not type anything. I quit the terminal and now all I get is the word 'terminal' in the menubar with a little spinning circle for a little bit and then it disappears.
I commented out the lines in .bashrc about virtualenv but no joy.
EDIT:
Using xterm I did this
cd /usr/bin
sudo rm python3
sudo ln -s python3.6 python3
and rebooted.
Now I got my terminal back. python3 points to python 3.6.7. But I'm afraid of switching the symlink to 3.7.
UPDATE:
Even disabling virtualenv in .bashrc, rebooting, and trying to switch back to python3.7 reproduces the problem. I can invoke python3.7 directly from the command line and see the python3.7.1 prompt >>> but it seems the system does not like it to be the default python3.
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.
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.
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.