Unable to install pyinstaller in Ubuntu 16 with Python3.5 - python-3.x

I have ubuntu16 which comes with python3.5 pre installed. I have installed pyinstaller using:
sudo pip3 install pyinstaller
It ran fine and installed pyinstaller. After that I ran, pyinstaller it says command not found.
I also tried installing it like:
sudo python3 -m pip install pyinstaller
It ran fine and said requirement already satisfied. But was unable to run pyinstaller.
I then upgraded the pip using sudo python3 -m pip install --upgrade pip and then reinstalled pyinstaller but this time used --user flag:
sudo python3 -m pip install pyinstaller --user
After this command it installed pyinstaller along with some other packages too.
Now if I run pyinstaller on terminal, I get this error:
Traceback (most recent call last):
File "/home/andrew/.local/bin/pyinstaller", line 5, in <module>
from PyInstaller.__main__ import run
ImportError: No module named 'PyInstaller'
Running the command sudo python3 -m pip list to get all the installed packages, I can see pyinstaller in the list:
pycurl 7.43.0
pygobject 3.20.0
pyinstaller 4.0
pyinstaller-hooks-contrib 2020.9
PyJWT 1.3.0
I am really confused as to what I should do in order to successfully install and run pyinstaller. Can anyone please help and suggest some good working solutions. Thanks

Okay I think I have finally managed to run pyinstaller on ubuntu16.
I am not sure if its the issue with Ubuntu16 or python3.5, but we need to upgrade the python version. So I first installed python3.6 using below commands:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.6
After the installation, I made sure that running python3 is invoking the python3.6 and not python3.5:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 2
sudo update-alternatives --config python3
After this if you type in python3, it should launch python3.6.
Once this is all done, just upgrade pip :
sudo python3 -m pip install --upgrade pip
after that you can install pyinstaller:
sudo pip3 install pyinstaller
also run this command:
sudo apt-get install python3.6-dev
otherwise you will get python lib not found error in pyinstaller build
and it will install and work fine.
I think pyinstaller is not working with python3.5 as this python version is also deprecated. So we need to upgrade the python version. So if any one is on ubuntu16 which has python3.5 as default, just upgrade your python version.

Related

Installing PyQt5 on Raspberry (Buster) with Python 3.7.3 [duplicate]

I need to port some code that's Python2+PyQt4 to Python3+PyQt5.
I started installing pip3
sudo apt-get install python3-pip
Works great. Tried
sudo pip3 install PyQt5
Downloading/unpacking PyQt5
Could not find any downloads that satisfy the requirement PyQt5
Cleaning up...
No distributions at all found for PyQt5
Online I find the following steps:
http://pyqt.sourceforge.net/Docs/PyQt5/installation.html
But they are too many. What's the easiest way to Install PyQt5 along with Python3 in Ubuntu 14.04 ?
Why not simply install it via apt-get?
sudo apt-get install python3-pyqt5
Otherwise you'd have to compile PyQt (and potentially Qt) by hand, which is cumbersome.
Well I documented the steps for Installing pyqt5 with qt designer and code generation here: https://gist.github.com/ujjwal96/1dcd57542bdaf3c9d1b0dd526ccd44ff
Installation
pip3 install --user pyqt5
sudo apt-get install python3-pyqt5
sudo apt-get install pyqt5-dev-tools
sudo apt-get install qttools5-dev-tools
Configuring to run from terminal
$ qtchooser -run-tool=designer -qt=5
OR
Write the following in /usr/lib/x86_64-linux-gnu/qt-default/qtchooser/default.conf
/usr/lib/x86_64-linux-gnu/qt5/bin
/usr/lib/x86_64-linux-gnu
Code Generation
Create uic.py file.
#!/usr/bin/python3
import subprocess
import sys
child = subprocess.Popen(['pyuic5' ,'-x',sys.argv[1]],stdout=subprocess.PIPE)
print(str(child.communicate()[0],encoding='utf-8'))
$ chmod +x uic.py
Create a symlink:
$ sudo ln uic.py "/usr/lib/x86_64-linux-gnu/qt5/bin/uic"
Desktop Entry
[Desktop Entry]
Name=Qt5 Designer
Icon=designer
Exec=/usr/lib/x86_64-linux-gnu/qt5/bin/designer
Type=Application
Categories=Application
Terminal=false
StartupNotify=true
Actions=NewWindow
Name[en_US]=Qt5 Designer
[Desktop Action NewWindow]
Name=Open a New Window
Exec=/usr/lib/x86_64-linux-gnu/qt5/bin/designer
save in ~/.local/share/application with .desktop extension
sudo apt-get install python3-pip
sudo pip3 install PyQt5
How to install PyQt5 in Python3
Tested on Ubuntu 18.04.
Just installing it did not work for me. I had to uninstall it first, then reinstall it:
# upgrade pip
python3 -m pip install --upgrade pip
# uninstall
python3 -m pip uninstall PyQt5
python3 -m pip uninstall PyQt5-sip
python3 -m pip uninstall PyQtWebEngine
# reinstall
python3 -m pip install PyQt5
python3 -m pip install PyQt5-sip
python3 -m pip install PyQtWebEngine
See here for my full answer, including how to install it for a specific version of Python3, such as Python3.8: How to install PyQt5 in Python3

Can’t run pip3 due to import error after upgrade [duplicate]

Whenever I am trying to install any package using pip, I am getting this import error:
guru#guru-notebook:~$ pip3 install numpy
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
ImportError: cannot import name 'main'
guru#guru-notebook:~$ cat `which pip3`
#!/usr/bin/python3
# GENERATED BY DEBIAN
import sys
# Run the main entry point, similarly to how setuptools does it, but because
# we didn't install the actual entry point from setup.py, don't use the
# pkg_resources API.
from pip import main
if __name__ == '__main__':
sys.exit(main())
It was working fine earlier, I am not sure why it is throwing this error.
I have searched about this error, but can't find anything to fix it.
Please let me know if you need any further detail, I will update my question.
You must have inadvertently upgraded your system pip (probably through something like sudo pip install pip --upgrade)
pip 10.x adjusts where its internals are situated. The pip3 command you're seeing is one provided by your package maintainer (presumably debian based here?) and is not a file managed by pip.
You can read more about this on pip's issue tracker
You'll probably want to not upgrade your system pip and instead use a virtualenv.
To recover the pip3 binary you'll need to sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall.
If you want to continue in "unsupported territory" (upgrading a system package outside of the system package manager), you can probably get away with python3 -m pip ... instead of pip3.
We can clear the error by modifying the pip file.
Check the location of the file:
$ which pip
path -> /usr/bin/pip
Go to that location(/usr/bin/pip) and open terminal
Enter: $ sudo nano pip
You can see:
import sys
from pip import main
if __name__ == '__main__':
sys.exit(main())
Change to:
import sys
from pip import __main__
if __name__ == '__main__':
sys.exit(__main__._main())
then ctrl + o write the changes and exit
Hope this will do!!
For Ubuntu family, Debian, Linux Mint users
Thanks to Anthony's explanation above, you can retain your original system pip (in /usr/bin/ and dist-packages/) and remove the manually-installed pip (in ~/.local/) to resolve the conflict:
$ python3 -m pip uninstall pip
Ubuntu/Debian pip v8.1.1 (16.04) from python3-pip debian package (see$ pip3 -V) shows the same search results as the latest pip v10.0.1, and installs latest modules from PyPI just fine. It has a working pip command (already in the $PATH), plus the nice --user option patched-in by default since 2016. Looking at pip release notes, the newer versions are mostly about use-case specific bug fixes and certain new features, so not everyone has to rush upgrading pip just yet. And the new pip 10 can be deployed to Python virtualenvs, anyway.
But regardless of pips, your OS allows to quickly install common Python modules (including numpy) with APT, without the need for pip, for example:
$ sudo apt install python3-numpy python3-scipy (with system dependencies)
$ sudo apt install python3-pip (Debian-patched pip, slightly older but it doesn't matter)
Quick apt syntax reminder (please see man apt for details):
$ sudo apt update (to resync Ubuntu package index files from up-to-date sources)
$ apt search <python-package-name> (full text-search on all available packages)
$ apt show <python-package-name> (displays the detailed package description)
$ sudo apt install <python-package-name>
Package names prefixed with python- are for Python 2; and prefixed with python3- are for Python 3 (e.g. python3-pandas). There are thousands, and they undergo integration testing within Debian and Ubuntu. Unless you seek to install at per-user level (pip install --user option) or within virtualenv/venv, apt could be what you needed. These system packages are accessible from virtual envs too, as virtualenv will gracefully fall back to using system libs on import if your envs don't have given copies of modules.
Your custom-installed (with pip --user) per-user modules in ~/.local/lib will override them too.
Note, since this is a system-wide installation, you'd rarely need to remove them (need to be mindful about OS dependencies). This is convenient for packages with many system dependencies (such as with scipy or matplotlib), as APT will keep track and provide all required system libs and C extensions, while with pip you have no such guarantees.
In fact, for system-wide Python packages (in contrast to per-user, home dir level, or lower), Ubuntu expects using the APT package manager (rather than sudo pip) to avoid breaking OS: sudo pip3 targets the very same /usr/lib/python3/dist-packages directory where APT stores OS-sensitive modules. Recent Debian/Ubuntu releases depend heavily on Python 3, so its pre-installed modules are managed by apt and shouldn't be changed.
So if you use pip3 install command, please ensure that it runs in an isolated virtual dev environment, such as with virtualenv (sudo apt install python3-virtualenv), or with Python3 built-in (-m venv), or at a per-user level (--user pip option, default in Ubuntu-provided pip since 2016), but not system-wide (never sudo pip3!), because pip interferes with the operation of the APT package manager and may affect Ubuntu OS components when a system-used python module is unexpectedly changed. Good luck!
P. S. All the above is for the 'ideal' solution (Debian/Ubuntu way).
If you still want to use the new pip3 v10 exclusively, there are 3 quick workarounds:
simply open a new bash session (a new terminal tab, or type bash) - and pip3 v10 becomes available (see pip3 -V). debian's pip3 v8 remains installed but is broken; or
the command $ hash -d pip3 && pip3 -V to refresh pip3 pathname in the $PATH. debian's pip3 v8 remains installed but is broken; or
the command $ sudo apt remove python3-pip && hash -d pip3 to uninstall debian's pip3 v8 completely, in favor of your new pip3 v10.
Note: You will always need to add --user flag to any non-debian-provided pip, unless you are in a virtualenv! (it deploys python packages to ~/.local/, default in debian/ubuntu-provided python3-pip and python-pip since 2016). Your use of pip 10 system-wide, outside of virtualenv, is not really supported by Ubuntu/Debian. Never sudo pip3!
Further details:
https://github.com/pypa/pip/issues/5221#issuecomment-382069604
https://github.com/pypa/pip/issues/5240#issuecomment-381673100
resolved in one step only.
I too faced this issue, But this can be resolved simply by 1 command without bothering around and wasting time and i have tried it on multiple systems it's the cleanest solution for this issue. And that's:
For python3:- sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall.
By this , you can simply install packages using pip3. to check use pip3 --version.
For older versions, use : sudo python -m pip uninstall pip && sudo apt install python-pip --reinstall.
By this, now you can simply install packages using pip. to check use pip --version.
Use python -m pip install instead of pip install
Example:
python -m pip install --user somepackage
python3 -m pip install --user somepackage
The pip (resp. pip3) executable is provided by your distro (python-pip package on Ubuntu 16.04) and located at /usr/bin/pip.
Therefore, it is not kept up-to date with the pip package itself as you upgrade pip, and may break.
If you just use python -m pip directly, e.g. as in:
python -m pip install --user somepackage
python3 -m pip install --user somepackage
it goes through your Python path, finds the latest version of pip and executes that file.
It relies on the fact that file is executable through import, but that is a very standard type of interface, and therefore less likely to break than the hackier Debian script.
Then I recommend adding the following aliases to your .bashrc:
pip() ( python -m pip "$#" )
pip3() ( python3 -m pip "$#" )
The Ubuntu 18.04 /usr/bin/pip3 file does:
from pip import main
and presumably main was removed from pip at some point which is what broke things.
The breaking pip commit appears to be: 95bcf8c5f6394298035a7332c441868f3b0169f4 "Move all internal APIs to pip._internal" which went into pip 18.0.
Tested in Ubuntu 16.04 after an update from pip3 9.0.1 to 18.0.
pyenv
Ultimately however, for serious Python development I would just recommend that you install your own local Python with pyenv + virtualenv, which would also get around this Ubuntu bug: https://askubuntu.com/questions/682869/how-do-i-install-a-different-python-version-using-apt-get/1195153#1195153
You can resolve this issue by reinstalling pip.
Use one of the following command line commands to reinstall pip:
Python2:
python -m pip uninstall pip && sudo apt install python-pip --reinstall
Python3:
python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall
Check if pip has been cached on another path, to do so, call $ which pip and check that the path is different from the one prompted in the error, if that's the case run:
$ hash -r
When the cache is clear, pip will be working again.
reference: http://cheng.logdown.com/posts/2015/06/14/-usr-bin-pip-no-such-file-or-directory
I'm running on a system where I have sudo apt but no sudo pip. (And no su access.) I got myself into this same situation by following the advice from pip:
You are using pip version 8.1.1, however 18.0 is available. You should consider upgrading via the 'pip install --upgrade pip' command.
None of the other fixes worked for me, because I don't have enough admin privileges. However, a few things stuck with me from reading up on this:
I shouldn't have done this. Sure, pip told me to. It lied.
Using --user solves a lot of issues by focusing on the user-only directory.
So, I found this command line to work to revert me back to where I was. If you were using a different version than 8.1.1, you will obviously want to change that part of the line.
python -m pip install --force-reinstall pip==8.1.1 --user
That's the only thing that worked for me, but it worked perfectly!
I met the same problem on my Ubuntu 16.04 system. I managed to fix it by re-installing pip with the following command:
curl https://bootstrap.pypa.io/get-pip.py | sudo python3
Recover with python3 -m pip install --user pip==9.0.1 (or the version that worked)
Same thing happened to me on Pixelbook using the new LXC (strech). This solution is very similar to the accepted one, with one subtle difference, whiched fixed pip3 for me.
sudo python3 -m pip install --upgrade pip
That bumped the version, and now it works as expected.
I found it here ... Python.org: Ensure pip is up-to-date
The commands above didn't work for me but those were very helpful:
sudo apt purge python3-pip
sudo rm -rf '/usr/lib/python3/dist-packages/pip'
sudo apt install python3-pip
cd
cd .local/lib/python3/site-packages
sudo rm -rf pip*
cd
cd .local/lib/python3.5/site-packages
sudo rm -rf pip*
sudo pip3 install jupyter
In ubuntu 18.04.1 Bionic Beaver, you need to log out and log back in (restart not necessary) to get the proper environment.
$ sudo apt install python-pip
$ pip --version
pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)
$ pip install --upgrade pip
$ pip --version
Traceback (most recent call last):
File "/usr/bin/pip", line 9, in <module>
from pip import main
ImportError: cannot import name main
$ exit
<login>
$ pip --version
pip 18.1 from /home/test/.local/lib/python2.7/site-packages/pip (python 2.7)
I use sudo apt remove python3-pip then pip works.
~ sudo pip install pip --upgrade
[sudo] password for sen:
Traceback (most recent call last):
File "/usr/bin/pip", line 9, in <module>
from pip import main
ImportError: cannot import name 'main'
➜ ~ sudo apt remove python3-pip
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libexpat1-dev libpython3-dev libpython3.5-dev python-pip-whl python3-dev python3-wheel
python3.5-dev
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
python3-pip
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 569 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 215769 files and directories currently installed.)
Removing python3-pip (8.1.1-2ubuntu0.4) ...
Processing triggers for man-db (2.7.5-1) ...
➜ ~ pip
Usage:
pip <command> [options]
For Python version 2.7 #Anthony solution works perfect, by changing python3 to python as follows:
sudo python -m pip uninstall pip && sudo apt install python-pip --reinstall
What worked for me to fix the error with using pip3 was:
sudo cp -v /usr/local/bin/pip3 /usr/bin/pip3
Everything works:
demon#UbuntuHP:~$ pip -V
pip 10.0.1 from /usr/local/lib/python3.5/dist-packages/pip (python 3.5)
demon#UbuntuHP:~$ pip2 -V
pip 10.0.1 from /home/demon/.local/lib/python2.7/site-packages/pip (python 2.7)
demon#UbuntuHP:~$ pip3 -V
pip 10.0.1 from /usr/local/lib/python3.5/dist-packages/pip (python 3.5)
Maybe the new 10.0.1 version of pip doesn't update the binary in /usr/bin ? (which seems it does not)
EDIT: the same issue occurs in Ubuntu 18.04. The best solution I've found is to symlink the pip binaries from /home/<user/.local/bin to /usr/local/bin or /usr/bin (depending on your preference), as follows:
ln -sv /home/<user>/.local/bin/pip /usr/local/bin/pip
ln -sv /home/<user>/.local/bin/pip2 /usr/local/bin/pip2
ln -sv /home/<user>/.local/bin/pip2.7 /usr/local/bin/pip2.7
ln -sv /home/<user>/.local/bin/pip3 /usr/local/bin/pip3
ln -sv /home/<user>/.local/bin/pip3.6 /usr/local/bin/pip3.6
NOTE: replace <user> with your current running user
The associated versions (latest) are in:
Version 3.6:
/home/demon/.local/lib/python3.6/site-packages/pip (python 3.6)
Version 2.7:
/home/demon/.local/lib/python2.7/site-packages/pip (python 2.7)
Trick and works too
sudo -H pip install lxml
I had this same error, but python -m pip was still working, so I fixed it with the nuclear option sudo python -m pip install --upgrade pip. It did it for me.
For what it's worth, I had the problem with pip (not pip2 or pip3):
$ pip -V
Traceback (most recent call last):
File "/usr/bin/pip", line 9, in <module>
from pip import main
ImportError: cannot import name main
$ pip2 -V
pip 8.1.1 from /usr/lib/python2.7/dist-packages (python 2.7)
$ pip3 -V
pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)
Somehow (I can't remember how) I had python stuff installed in my ~/.local directory. After I removed the pip directory from there, pip started working again.
$ rm -rf /home/precor/.local/lib/python2.7/site-packages/pip
$ pip -V
pip 8.1.1 from /usr/lib/python2.7/dist-packages (python 2.7)
Is something wrong with the packages, when it generating de file /usr/bin/pip,
you have to change the import:
from pip import main
to
from pip._internal import main
That solves the problem, I'm not sure why it generated, but it saids somthing in the following issue:
After pip 10 upgrade on pyenv "ImportError: cannot import name 'main'"
You can try this:
sudo ln -sf $( type -P pip ) /usr/bin/pip
I also run into this problem when I wanted to upgrade system pip pip3 from 9.0.1 to 19.2.3.
After running pip3 install --upgrade pip, pip version becomes 19.2.3. But main() has been moved in pip._internal in the latest version, which leaves pip3 broken.
So in file /usr/bin/pip3, replace line 9: from pip import main with from pip._internal import main. The issue will be fixed, works the same for python2-pip. (Tested on Ubuntu 18.04 distribution)
According to #Vincent H.'s answer
Please run the following commands to do the fix. After running python3 -m pip install --upgrade pip, please run the following command.
hash -r pip
Source: https://github.com/pypa/pip/issues/5221
you can simply fix the pip and pip3 paths using update-alternatives
first thing you should check is your current $PATH
run echo $PATH and see is you can find /usr/local/bin which is where pip3 and pip usually are
there is a change your system is looking here /bin/pip and /bin/pip3
so i will say fix the PATH by adding to your ~/.bash_profile file so it persists
export PATH=$PATH:/usr/local/bin
and then check is its fixed with which pip and which pip3
if not then use update-alternatives to fix it finally
update-alternatives --install /bin/pip3 pip3 /usr/local/bin/pip3 30
and if you want to point pip to pip3 then
update-alternatives --install /bin/pip pip /usr/local/bin/pip3 30
I have the same problem and solved it. Here is my solution.
First, when I run pip install something, the error came out like this:
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
ImportError: cannot import name 'main'
So, I cd into the file /usr/bin/ and cat pip3 to see the code in it. I see this in it:
#!/usr/bin/python3
# GENERATED BY DEBIAN
import sys
# Run the main entry point, similarly to how setuptools does it, but because
# we didn't install the actual entry point from setup.py, don't use the
# pkg_resources API.
from pip import main
if __name__ == '__main__':
sys.exit(main())
And then I think that it was not in the installation path. So I cd into the python3-pip, like this:
cd /.local/lib/python3.5/site-packages/pip
P.S.: you have to cd into the right directions in your computer
Then I cat the file to see the differences(you can use other operations to see the code):
cat __main__.py
And I saw this:
from __future__ import absolute_import
import os
import sys
# If we are running from a wheel, add the wheel to sys.path
# This allows the usage python pip-*.whl/pip install pip-*.whl
if __package__ == '':
# __file__ is pip-*.whl/pip/__main__.py
# first dirname call strips of '/__main__.py', second strips off '/pip'
# Resulting path is the name of the wheel itself
# Add that to sys.path so we can import pip
path = os.path.dirname(os.path.dirname(__file__))
sys.path.insert(0, path)
from pip._internal import main as _main # isort:skip # noqa
if __name__ == '__main__':
sys.exit(_main())
So, can you see the difference? I can figure out that I have to make the file the same as the file in /usr/bin/pip3
So, I copied the code in /.local/lib/python3.5/site-packages/pip to replace the code in /usr/bin/pip3
and the problem disappear!
P.S.: pip3 or pip have no difference in this problem.
I will be happy if my solution solve your problem!
This Worked for me !
hash -r pip # or hash -d pip
Now, uninstall the pip installed version and reinstall it using the following commands.
python -m pip uninstall pip # sudo
sudo apt install --reinstall python-pip
If pip is broken, use:
python -m pip install --force-reinstall pip
Hope it helps!
I used the following code to load a module that might need install, thus avoiding this error (which I also got) - using the latest Python and latest pip with no problem
try
from colorama import Fore, Back, Style
except:
!pip install colorama
from colorama import Fore, Back, Style
import main from pip._internal
from pip._internal import main
Edit the pip code from
sudo nano /usr/bin/pip3
As #cryptoboy said - check what pip/python version you have installed
demon#UbuntuHP:~$ pip -V
demon#UbuntuHP:~$ pip2 -V
demon#UbuntuHP:~$ pip3 -V
and then check for no-needed libraries in your .local/lib/ folder.
I did backup of settings when I was migrating to newer Kubuntu and in had .local/lib/python2.7/ folder in my home directory. Installed python 3.6. I just removed the old folder and now everything works great!
On Debian you will need to update apt first....
sudo apt-get update -qq
sudo apt-get install python-pip -qq
sudo pip install pip --upgrade --quiet
sudo pip2 install virtualenv --quiet
If you skip 'sudo apt-get update -qq' your pip will become corrupt and display the 'cannot find main' error.

How to install pip for Python 3.6 on Ubuntu 16.10?

I'd like to start by pointing out that this question may seem like a duplicate, but it isn't. All the questions I saw here were regarding pip for Python 3 and I'm talking about Python 3.6. The steps used back then don't work for Python 3.6.
I got a clear Ubuntu 16.10 image from the official docker store.
Run apt-get update
Run apt-get install python3.6
Run apt-get install python3-pip
Run pip3 install requests bs4
Run python3.6 script.py
Got ModuleNotFoundError below:
Traceback (most recent call last):
File "script.py", line 6, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
Python's and pip's I have in the machine:
python3
python3.5
python3.5m
python3.6
python3m
python3-config
python3.5-config
python3.5m-config
python3.6m
python3m-config
pip
pip3
pip3.5
Let's suppose that you have a system running Ubuntu 16.04, 16.10, or 17.04, and you want Python 3.6 to be the default Python.
If you're using Ubuntu 16.04 LTS, you'll need to use a PPA:
sudo add-apt-repository ppa:jonathonf/python-3.6 # (only for 16.04 LTS)
Then, run the following (this works out-of-the-box on 16.10 and 17.04):
sudo apt update
sudo apt install python3.6
sudo apt install python3.6-dev
sudo apt install python3.6-venv
wget https://bootstrap.pypa.io/get-pip.py
sudo python3.6 get-pip.py
sudo ln -s /usr/bin/python3.6 /usr/local/bin/python3
sudo ln -s /usr/local/bin/pip /usr/local/bin/pip3
# Do this only if you want python3 to be the default Python
# instead of python2 (may be dangerous, esp. before 2020):
# sudo ln -s /usr/bin/python3.6 /usr/local/bin/python
When you have completed all of the above, each of the following shell commands should indicate Python 3.6.1 (or a more recent version of Python 3.6):
python --version # (this will reflect your choice, see above)
python3 --version
$(head -1 `which pip` | tail -c +3) --version
$(head -1 `which pip3` | tail -c +3) --version
In at least in ubuntu 16.10, the default python3 is python3.5. As such, all of the python3-X packages will be installed for python3.5 and not for python3.6.
You can verify this by checking the shebang of pip3:
$ head -n1 $(which pip3)
#!/usr/bin/python3
Fortunately, the pip installed by the python3-pip package is installed into the "shared" /usr/lib/python3/dist-packages such that python3.6 can also take advantage of it.
You can install packages for python3.6 by doing:
python3.6 -m pip install ...
For example:
$ python3.6 -m pip install requests
$ python3.6 -c 'import requests; print(requests.__file__)'
/usr/local/lib/python3.6/dist-packages/requests/__init__.py
This answer assumes that you have python3.6 installed. For python3.7, replace 3.6 with 3.7. For python3.8, replace 3.6 with 3.8, but it may also first require the python3.8-distutils package.
Installation with sudo
With regard to installing pip, using curl (instead of wget) avoids writing the file to disk.
curl https://bootstrap.pypa.io/get-pip.py | sudo -H python3.6
The -H flag is evidently necessary with sudo in order to prevent errors such as the following when installing pip for an updated python interpreter:
The directory '/home/someuser/.cache/pip/http' or its parent directory
is not owned by the current user and the cache has been disabled.
Please check the permissions and owner of that directory. If executing
pip with sudo, you may want sudo's -H flag.
The directory
'/home/someuser/.cache/pip' or its parent directory is not owned by the
current user and caching wheels has been disabled. check the
permissions and owner of that directory. If executing pip with sudo,
you may want sudo's -H flag.
Installation without sudo
curl https://bootstrap.pypa.io/get-pip.py | python3.6 - --user
This may sometimes give a warning such as:
WARNING: The script wheel is installed in '/home/ubuntu/.local/bin'
which is not on PATH. Consider adding this directory to PATH or, if
you prefer to suppress this warning, use --no-warn-script-location.
Verification
After this, pip, pip3, and pip3.6 can all be expected to point to the same target:
$ (pip -V && pip3 -V && pip3.6 -V) | uniq
pip 18.0 from /usr/local/lib/python3.6/dist-packages (python 3.6)
Of course you can alternatively use python3.6 -m pip as well.
$ python3.6 -m pip -V
pip 18.0 from /usr/local/lib/python3.6/dist-packages (python 3.6)
This website contains a much cleaner solution, it leaves pip intact as-well and one can easily switch between 3.5 and 3.6 and then whenever 3.7 is released.
http://ubuntuhandbook.org/index.php/2017/07/install-python-3-6-1-in-ubuntu-16-04-lts/
A short summary:
sudo apt-get install python python-pip python3 python3-pip
sudo add-apt-repository ppa:jonathonf/python-3.6
sudo apt-get update
sudo apt-get install python3.6
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 2
Then
$ pip -V
pip 8.1.1 from /usr/lib/python2.7/dist-packages (python 2.7)
$ pip3 -V
pip 8.1.1 from /usr/local/lib/python3.5/dist-packages (python 3.5)
Then to select python 3.6 run
sudo update-alternatives --config python3
and select '2'. Then
$ pip3 -V
pip 8.1.1 from /usr/local/lib/python3.6/dist-packages (python 3.6)
To update pip select the desired version and
pip3 install --upgrade pip
$ pip3 -V
pip 9.0.1 from /usr/local/lib/python3.6/dist-packages (python 3.6)
Tested on Ubuntu 16.04.
Some of the solutions above using the script get-pip.py worked until a couple of weeks ago.
The latest version of this script now requires python3.7 throwing the following error
ERROR: This script does not work on Python 3.6
The minimun supported Python version is 3.7.
Please use https://bootstrap.pypa.io/pip/3.6/get-pip.py instead.
So making the corresponding change works now.
wget https://bootstrap.pypa.io/pip/3.6/get-pip.py
sudo python3.6 get-pip.py

How to install PyQt5 in Python 3 (Ubuntu 14.04)

I need to port some code that's Python2+PyQt4 to Python3+PyQt5.
I started installing pip3
sudo apt-get install python3-pip
Works great. Tried
sudo pip3 install PyQt5
Downloading/unpacking PyQt5
Could not find any downloads that satisfy the requirement PyQt5
Cleaning up...
No distributions at all found for PyQt5
Online I find the following steps:
http://pyqt.sourceforge.net/Docs/PyQt5/installation.html
But they are too many. What's the easiest way to Install PyQt5 along with Python3 in Ubuntu 14.04 ?
Why not simply install it via apt-get?
sudo apt-get install python3-pyqt5
Otherwise you'd have to compile PyQt (and potentially Qt) by hand, which is cumbersome.
Well I documented the steps for Installing pyqt5 with qt designer and code generation here: https://gist.github.com/ujjwal96/1dcd57542bdaf3c9d1b0dd526ccd44ff
Installation
pip3 install --user pyqt5
sudo apt-get install python3-pyqt5
sudo apt-get install pyqt5-dev-tools
sudo apt-get install qttools5-dev-tools
Configuring to run from terminal
$ qtchooser -run-tool=designer -qt=5
OR
Write the following in /usr/lib/x86_64-linux-gnu/qt-default/qtchooser/default.conf
/usr/lib/x86_64-linux-gnu/qt5/bin
/usr/lib/x86_64-linux-gnu
Code Generation
Create uic.py file.
#!/usr/bin/python3
import subprocess
import sys
child = subprocess.Popen(['pyuic5' ,'-x',sys.argv[1]],stdout=subprocess.PIPE)
print(str(child.communicate()[0],encoding='utf-8'))
$ chmod +x uic.py
Create a symlink:
$ sudo ln uic.py "/usr/lib/x86_64-linux-gnu/qt5/bin/uic"
Desktop Entry
[Desktop Entry]
Name=Qt5 Designer
Icon=designer
Exec=/usr/lib/x86_64-linux-gnu/qt5/bin/designer
Type=Application
Categories=Application
Terminal=false
StartupNotify=true
Actions=NewWindow
Name[en_US]=Qt5 Designer
[Desktop Action NewWindow]
Name=Open a New Window
Exec=/usr/lib/x86_64-linux-gnu/qt5/bin/designer
save in ~/.local/share/application with .desktop extension
sudo apt-get install python3-pip
sudo pip3 install PyQt5
How to install PyQt5 in Python3
Tested on Ubuntu 18.04.
Just installing it did not work for me. I had to uninstall it first, then reinstall it:
# upgrade pip
python3 -m pip install --upgrade pip
# uninstall
python3 -m pip uninstall PyQt5
python3 -m pip uninstall PyQt5-sip
python3 -m pip uninstall PyQtWebEngine
# reinstall
python3 -m pip install PyQt5
python3 -m pip install PyQt5-sip
python3 -m pip install PyQtWebEngine
See here for my full answer, including how to install it for a specific version of Python3, such as Python3.8: How to install PyQt5 in Python3

GoogleScraper (Python Script) error: "pkg_resources.DistributionNotFound: aiohttp"

I am trying to get GoogleScraper Python script working on Ubuntu 14.04 LTS, but am getting the following error when I type "./GoogleScraper -h"
<code>
./GoogleScraper -h
Traceback (most recent call last):
File "./GoogleScraper", line 5, in <module>
from pkg_resources import load_entry_point
File "/home/roger/env/lib/python3.4/site-packages/pkg_resources.py", line 2716, in <module>
working_set.require(__requires__)
File "/home/roger/env/lib/python3.4/site-packages/pkg_resources.py", line 685, in require
needed = self.resolve(parse_requirements(requirements))
File "/home/roger/env/lib/python3.4/site-packages/pkg_resources.py", line 588, in resolve
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: aiohttp
</code>
What do I do to install this aiohttp package? I googled and was a little confused.
Here is my "Python -V" output
roger#vbox-ubuntu:~/env/bin$ python -V
Python 2.7.6
roger#vbox-ubuntu:~/env/bin$ python3 -V
Python 3.4.0
I also ran the following prior:
virtualenv --python python3 env
source env/bin/activate
pip install GoogleScraper
sudo apt-get install python3-pip
sudo pip3 install aiohttp
sudo pip3 install aiohttp
should fix your problem (preceded by sudo apt-get install python3-pip if pip is not installed yet)
Looks like much of my problem was running "sudo apt-get install" in my local environment.
My fix was starting with a fresh Ubuntu 14.04 LTS install and then running the following:
sudo apt-get install python-virtualenv python3-pip liblz-dev python-dev libxml2-dev libxslt-dev zlib1g-dev python3-dev libmysqlclient-dev ubuntu-desktop chromium-chromedriver google-chrome-stable
After that, I ran the following commands on the author's website:
virtualenv --python python3 env
source env/bin/activate
pip install GoogleScraper
sudo pip3 install aiohttp
After that, I was able to get "GoogleScraper -h" to output the help file, as expected.

Resources