1

Having just read this comment on upgrading pip, I ran:

sudo pip3 install --upgrade pip

As @ByteCommander points out, the upgrade goes to /usr/local/bin/pip3, while the distribution's version (from python3-pip) is located at /usr/bin/pip3, and the first has precedence due to the order in PATH. That seems to work fine, but if I specifically run the Ubuntu's version (16.04) I get an error:

/usr/bin/pip3 -V
Traceback (most recent call last):
  File "/usr/bin/pip3", line 9, in <module>
    from pip import main
ImportError: cannot import name 'main'

This is making me leery of python upgrades. So, I'm stuck trying to install a python package that's actually from a git repo and which is not in any apt-get repos, and which also has dependencies.

3 Answers 3

2

My opinion after many years of experience dealing with Python dependency issues is that you should not upgrade system Python packages outside of apt. This always causes these types of problems. The system package manager provides stable versions of Python and various Python packages with a complex dependency system, and when you try manually changing these outside of apt, it can cause a mess.

I would recommend purging python-pip, reinstalling the version provided by apt, and then only using the system Python for system related tasks and small scripts that don’t need extra packages. For development work which requires other packages that you would normally install with pip, you can either create virtual environments (which are basically new Python installations that won’t affect the system Python), or even better (IMO), install Anaconda Python which allows you to install Python packages with pip and conda without breaking the system Python.

1
  • Yes, purging/reinstalling is what the second link in my answer says to do. It also mentions virtual environments - though I have never used them before - along with installing via --user. Could you explain - would installing with --user not work just as well? My difficulty is that I'm trying to install a python package that's actually from a git repo and which is not in any apt-get repos.
    – Diagon
    Aug 25, 2018 at 23:10
1

As the link pointed to by @siddesh-chavan shows, there are some problems with the interface of apt-get and the python package manager. I would not recommend that linked solution. Instead, I believe it's best to read this, and if you've already upgraded pip/pip3, then downgrade this way. The upshot is, do not upgrade the system's pip or pip3. Do installs and upgrades locally, using pip* install --user.

The answer below that second link also mentions virtual environments, as does @steve in his answer - see below.

0

There is already a post on this.

https://stackoverflow.com/questions/28210269/importerror-cannot-import-name-main-when-running-pip-version-command-in-windo

This worked for me.

1
  • Thanks @siddesh-chavan. That seems to work, but this issue was merely lead-in to the second part, "This is making me leery of python upgrades." I failed to install the most recent version of aiohttp, needed for stig, and am uncertain how to handle the situation (see above).
    – Diagon
    Aug 25, 2018 at 3:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .