pip install not working. How to resolve pip precedence issues? - python

[qq88#qq88-pc ~]$ which -a pip
/home/qq88/.local/bin/pip
/usr/bin/pip
So it seems that after the python 3.8 update there is a conflict between which install takes precedence - right now it is /home/qq88/.local/bin/pip and not /usr/bin/pip. This causes issues when doing pip install like:
[qq88#qq88-pc ~]$ pip install ipython
Traceback (most recent call last):
File "/home/qq88/.local/bin/pip", line 10, in <module>
sys.exit(main())
TypeError: 'module' object is not callable
I went and installed it with python -m pip install ipython but:
[qq88#qq88-pc ~]$ ipython
Traceback (most recent call last):
File "/home/qq88/.local/bin/ipython", line 6, in <module>
from IPython import start_ipython
ModuleNotFoundError: No module named 'IPython'
How do I run this now?
And more importantly, how do I make /usr/bin/pip take precedence or whatever else would resolve this?

I think you can do it using the alias in your shell:
$ alias pip='/usr/bin/pip'
Then if you execute $ alias pip you should get :
alias pip='/usr/bin/pip'

Related

No Module named pip when running it

When I use pip3 I get this error:
Traceback (most recent call last):
File "/Library/Developer/CommandLineTools/usr/bin/pip3", line 7, in <module>
from pip import main
ModuleNotFoundError: No module named 'pip'
I tried to reinstall PIP but still reported this error, but I use python3 -m ensurepip
It told me to install Xcode command line
$ python3 -m ensurepip
$ xcode-select: Failed to locate 'python3.9', requesting installation of command line developer tools.
I had this problem when I was trying to update the pip and it failed.
This always works for me:
Download the script, from https://bootstrap.pypa.io/get-pip.py.
Open a terminal/command prompt, cd to the folder containing the get-pip.py file and run:
python get-pip.py
font: https://pip.pypa.io/en/stable/installation/
Try to install python3.9 as suggested by the terminal.

Unable to install python3.6 virtualenv in Ubuntu 19.10 ('no module named apport')

I've upgraded my ubuntu distro to 19.10 and now I can't install virtualenv for python3.6. I can create virtualenv for python3.7 with no issues by typing 'virtualenv NAME --python=python3' but when I replace python3 with python3.6, I get the following output.
Running virtualenv with interpreter /usr/bin/python3.6
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/virtualenv.py", line 25, in <module>
import distutils.sysconfig
ModuleNotFoundError: No module named 'distutils.sysconfig'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
ModuleNotFoundError: No module named 'apport'
Python3.6 runs fine when I type in python3.6 into shell.
I have python3-pip, python3-setuptools and python3-distutils installed.
I reinstalled Ubuntu (fresh), installed python3.7-venv and python3.8-venv, installed python3.6 (manually) and it worked then with the command:
python3.6 -m venv NAME
Not sure which fixed it. I expected I'd need python3.6-venv but I didn't.

how to make pip works again?

I tried to make pip3 as the main pip in my Linux by writing this code
alias pip=pip3
and after that what ever command I give to pip, it keeps on giving the same error message:
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
ImportError: cannot import name 'main'
For linux, you can use the argument -m of python bin.
python3 -m pip
so, you can use this allias
alias pip="python3 -m pip"
Use python3 -m pip install --user packagename

Can't use Django in virtualenv

I have two Django projects and I created two different virtualenv for them.
When I create another one virtualenv and install Django and create a django project I tried python manage.py runserver and have this error:
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 14, in <module>
import django
ImportError: No module named 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 17, in <module>
"Couldn't import Django. Are you sure it's installed and "
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
What I need to do?
I already tried uninstalling Django, pip, virtualenv and re-install:
sudo apt-get install python3-pip
sudo pip3 install virtualenv
sudo virtualenv ENV
source newenv/bin/activate
sudo -H pip3 install django
Using sudo with virtualenvs can cause a lot of scope issues, as well as a virture of virtualenvs is that you shouldn't need root permissions for them (in most cases).
Also if you have virtaulenv installed for python 2 as well, it might be defaulting to that one.
sudo apt-get install python3-pip
sudo pip3 install virtualenv
# I prefer using this over `virtualenv --python=/usr/bin/python3 ENV`
python3 -m venv ENV
source ENV/bin/activate
# Can do a `which pip3` here to make sure it's using the ENV one
pip3 install django
# Could also do full path of `ENV/bin/pip3 install django`

python3.4 pip ImportError: No Module named 'pkg_resources'

pip is not working in my python3.4
$ pip install django
Traceback (most recent call last):
File "usr/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
ImportError: No module named 'pkg_resources'
$ pip
Traceback (most recent call last):
File "usr/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
ImportError: No module named 'pkg_resources'
How do I fix this? What's the problem? Thanks
i just ran into the same error, here is what i've done to fix it:
sudo apt-get remove --purge python-pkg-resources
sudo apt-get install ubuntu-desktop
Try >sudo pip install django< I think that ought to do it
well then I suspect your pip is messed up so try
sudo apt-get install --reinstall python-pkg-resources
however if you are using Python 3 you may need to adjust to insure that you get the Python 3 environment set up rather than the P2 default
see here for more on that
How to use pip with Python 3.x alongside Python 2.x

Categories

Resources