Some issues with pip installation - python

I tried to install pip manager using the file get-pip.py as mentioned in the documentation- https://pip.pypa.io/en/stable/installing/
So, I downloaded the file and ran python get-pip.py and as a result, I had permission issues. So I again ran sudo python get-pip.py and it worked.
Now I wanted to install numpy. So I ran pip install numpy and it showed me the Import Error saying-
Traceback (most recent call last):
File "/usr/local/bin/pip", line 7, in <module>
from pip import main
ImportError: No module named pip
But again when I ran sudo pip install numpy, it worked and got installed. Now, for every python script involving these pip packages, I have to run the script using sudo which I don't like. So how can I resolve these permission issues?
Just to mention-
python v2.7.12
pip v9.0.1
pip installation location- /usr/local/lib/python2.7/dist-packages

Related

Pipenv "ModuleNotFoundError: No module named 'pip'" after upgrading to python3.7

I am using ubuntu 18. The default python3 version is 3.6. I updated to 3.7 today and update the alternatives to point to python3.7.
I can use python3.7 by typing python3. I can also use pip3 --version (20.0.2).
I can activate the virtual environment by using pipenv shell. But I cannot install package using pipenv install . It gives me the following error:
pipenv.exceptions.InstallError]: ['Traceback (most recent call last):', ' File "/home/johnchan/.local/share/virtualenvs/src-lkQYyAWf/bin/pip", line 5, in <module>', ' from p
ip._internal.cli.main import main', "ModuleNotFoundError: No module named 'pip'"]
ERROR: ERROR: Package installation failed...
Running which pip3: /usr/local/bin/pip3
Running which pipenv: /usr/local/bin/pipenv
Type pip3 inside pipenv gives:
Traceback (most recent call last):
File "/home/johnchan/.local/share/virtualenvs/src-lkQYyAWf/bin/pip3", line 5, in <module>
from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip'
python2 -m pip install --user --upgrade pip
python3 -m pip install --user --upgrade pip
After upgrading pip (or pip3, in this case) if the following occurs:
$ ~ pip3 -V
Traceback (most recent call last):
File "/usr/local/bin/pip", line 7, in <module>
from pip._internal import main
ModuleNotFoundError: No module named 'pip._internal'
Force a reinstall of pip:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --force-reinstall
Verify install:
$ ~ pip3 -V
pip 10.0.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
Now pip3 install <package> and pip3 install --user <package> (for user-level installs) will work correctly.
There should never, ever be any reason you need to run pip in elevated mode.
(note: For Python 2.7, just replace python for python3, and pip for pip3)
Had the same issue on macOS as well, it's a common issue across platforms.
I found the answer here:
Setting up a virtualenv: No module named 'pip'
Seems like it is a bug.
I install pipenv using --re flag which is equivalent to virtualenv venv --no-setuptools.
Then I run python get-pip.py inside pipenv.
It works. I can install package now.
But I don't know the reason why...

Why is my pip braking after updating

My pip broke after I ran
pip install --upgrade pip
When I run this command
pip -V
or any other commands I get
Traceback (most recent call last):
File "/usr/bin/pip", line 9, in <module>
from pip import main
ImportError: cannot import name main
Why is it breaking? I have python3 installed. I have a solution but I need to understand why it broke after upgrading to the latest version.
pip authors were warning for many years to not import pip. Finally at version 10 they restructured their code.
Your /usr/bin/pip was not upgraded (probably because pip install -U pip installed new /usr/local/bin/pip) so it uses the old API before renaming.
If that's the case I recommend to put /usr/local/bin before /usr/bin in $PATH.

Python : setuptools module is already installed but still shows import error

I am trying to install something using "python setup.py install" but it shows me this error :-
Traceback (most recent call last):
File "setup.py", line 3, in <module>
from setuptools import setup
ImportError: No module named setuptools
I have installed this missing module using "pip install setuptools". But still it shows me the same error .I have also tried to install this using "sudo apt-get install python-setuptools" but the problem still remains the same. Help me in this issue
If you have Python 2 >=2.7.9 or Python 3 >=3.4 installed from python.org, you will already have pip and setuptools, but will need to upgrade to the latest version:
On Linux or macOS:
pip install -U pip setuptools
On Windows:
python -m pip install -U pip setuptools
If you’re using a Python install on Linux that’s managed by the system package manager (e.g “yum”, “apt-get” etc…), and you want to use the system package manager to install or upgrade pip, then see link

Unable to use tmuxp

I installed tmuxp using sudo pip install --user tmuxp. However I'm unable to load my profile work.yaml.
It throws error
Traceback (most recent call last):
File "/home/pranav/.local/bin/tmuxp", line 7, in <module>
from tmuxp import cli
ImportError: No module named tmuxp
I've followed https://github.com/tony/tmuxp instructions.
Uninstall: pip uninstall tmuxp
Assure the binary file is removed: rm ~/.local/bin/tmuxp
Reinstall: pip install --user tmuxp
Double check your python / pip configuration:
If the above doesn't work, there may be a larger issue with your pip installation, the problem may be a generic pip issue. 90% of the time this happens with PATHs from system's python mix up your user-level python.
Check which pip, which python and get an eye through tracebacks if your system's packages are mixing up with your local ones (e.g. /usr/local/python3.7/site-packages and ~/.somepath/python3.7/site-packages. If that is the case, consider clearing out all local pip packages and reinstalling pip through the get-pip.py installer.

Problems Installing pip on CentOS 5.x

I have pip installed:
[amr#h2oamr kits]$ python get-pip.py
Requirement already up-to-date: pip in /usr/local/lib/python2.7/site-packages
However, I'm getting this error when trying to install Django:
[amr#h2oamr kits]$ pip install django
Traceback (most recent call last):
File "/usr/local/bin/pip", line 7, in ?
from pip import main
ImportError: No module named pip
I am stuck trying to move forward. I installed pip as recommended by using a get-pip.py module I downloaded.
This upgrade also did not work.
[amr#h2oamr kits]$ pip install --upgrade pip
Traceback (most recent call last):
File "/usr/local/bin/pip", line 7, in ?
from pip import main
ImportError: No module named pip
How can I remove pip altogether, and then re-install it?
you can use the command $ rm pip to remove pip and then $sudo apt-get install pip to get the latest version

Categories

Resources