I have a problem when I try to use pip in any way. I'm using Ubuntu 16.04.4
I should say that I've used it already, and I never had any problem, but starting today when I use any command I always get the same error (as an example using pip --upgrade).
Traceback (most recent call last):
File "/usr/local/bin/pip", line 7, in <module>
from pip._internal import main
ImportError: No module named _internal
I have tried doing sudo apt-get remove python-pip followed by sudo apt-get install python-pip but nothing changed.
This did it for me:
python -m pip install --upgrade pip
Environment: OSX && Python installed via brew
An answer from askUbuntu works.
For pip2.7, you can at first curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py, then python2.7 get-pip.py --force-reinstall to reinstall pip.
Problem solved. Also works for python3.
This solution works for me:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --force-reinstall
or use sudo for elevated permissions (sudo python3 get-pip.py --force-reinstall).
Of course, you can also use python instead of python3 ;)
Source
Are you using python 2 or python 3? The following commands could be different!
run python3 -m pip --version to see if you have pip installed.
if yes, run python3 -m pip install --upgrade pip.
if no, run sudo apt-get install python3-pip, and do it again.
Refer to this issue list
sudo easy_install pip
works for me under Mac OS
For python3, may try sudo easy_install-3.x pip depends on the python 3.x version. Or python3 -m pip install --user --upgrade pip
This issue maybe due to common user do not have privilege to access packages py file.
1. root user can run 'pip list'
2. other common user cannot run 'pip list'
[~]$ pip list
Traceback (most recent call last):
File "/usr/bin/pip", line 7, in <module>
from pip._internal import main
ImportError: No module named pip._internal
Check pip py file privilege.
[root#]# ll /usr/lib/python2.7/site-packages/pip/
合計 24
-rw------- 1 root root 24 6月 7 16:57 __init__.py
-rw------- 1 root root 163 6月 7 16:57 __init__.pyc
-rw------- 1 root root 629 6月 7 16:57 __main__.py
-rw------- 1 root root 510 6月 7 16:57 __main__.pyc
drwx------ 8 root root 4096 6月 7 16:57 _internal
drwx------ 18 root root 4096 6月 7 16:57 _vendor
solution : root user login and run
chmod -R 755 /usr/lib/python2.7
fix this issue.
In file "/usr/local/bin/pip" change from pip._internal import main to from pip import main
For completeness, I just encountered this problem with "Ubuntu latest" ... v18.04 ... and fixed it in this way:
python3 -m pip install --upgrade pip
(Notice that it was necessary to specify python3 since this references Python 3.6.9. The python command on the same system references Python 2.7.17. Since this is apparently a system-wide installation it encountered a ["not sudo" ...] permission error, but it didn't matter because it was the wrong thing to do anyway. I was encountering the problem with pip3.)
I've seen this issue when PYTHONPATH was set to include the built-in site-packages directory. Since Python looks there automatically it is unnecessary and can be removed.
I just encountered the same problem and in my case, it turns out this is a conflict between the python installation in my virtualenv and the site-wide python (Ubuntu).
What solves it for me is to run pip in this way, to force usage of the correct python installation (in my vortualenv):
python3 -m pip install PACKAGE
instead of
pip3 install PACKAGE
I realised this when I tried to follow some of the answers here that suggest re-installing pip and the error output I got was pointing to an existing site-wide python library path although I had activated my virtualenv.
Worth trying before deleting and re-installing stuff.
For me
python -m pip uninstall pip
solved the issue. Reference
I tried the following command to solve the issue and it worked for me:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --force-reinstall
Its probably due to a version conflict, try to run this, it will remove the older pip somehow.
sudo apt remove python pip
I have fixed this error by running the following commands:
sudo apt remove python-pip
wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
It will remove the previously installed pip and reinstall it.
Thanks :)
Nothing worked for me, but only one thing:
I used sudo in front of the command and it is working fine.
I met the same error on Windows when I tried to install a package via pip3:
Traceback (most recent call last):
File "d:\anaconda\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "d:\anaconda\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "D:\Anaconda\Scripts\pip3.6.exe\__main__.py", line 5, in <module>
ModuleNotFoundError: No module named 'pip._internal'
My python is installed via Anaconda. I solved this issue by reinstalling pip via conda:
conda install pip
After that, pip returns to normal.
pip is not being installed properly on your "user", so try the following :
sudo python3 -m pip install --user --upgrade pip
The following solution solved the problem on my machine for python2.7
"$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py"
and then
"$ sudo python2.7 get-pip.py --force-reinstall"
For the current user only:
easy_install --user pip
or
python -m pip install --upgrade --user pip
The second may give /usr/bin/python: No module named pip
Even if which pip finds the module named pip.
In this case try the easy_install
Checking from pip documentation, this command worked to me:
python -m ensurepip --upgrade
I have the same problem on my virtual environment after upgrade python installation from 3.6 to 3.7 but only on vent globally pip work fine, to solve it I deactivate and delete my virtual environment after recreate again and now is fine, on venv:
deactivate
rm -rvf venv
and after recreate the virtual environment.
I use mac OS 10.11, and python 3
(On windows)
not sure why this was happening but I had my PYTHONPATH setup to point to c:\python27 where python was installed. in combination with virtualenv this produced the mentioned bug.
resolved by removing the PYTHONPATH env var all together
my solution:
first step like most other answer:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python2.7 get-pip.py --force-reinstall
second, add soft link
sudo ln -s /usr/local/bin/pip /usr/bin/pip
This command works for me.
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py --force-reinstall --user
you can remove it first, and install again ,it will be ok.
for centos:
yum remove python-pip
yum install python-pip
I fixed this problem by
sudo apt-get install python3-pip
this worked even for python2.7, amazing...
My solution is adding import pip to the script linked to the pip/pip3 commands.
Firstly, open the file (e.g. /usr/local/bin/pip) with your favorite text editor and the sudo mode. For example, I use sudo vim /usr/local/bin/pip to open the script file.
You will obtain some file as following:
import re
import sys
from pip._internal import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(main())
Afterwards, insert the statement import pip just before the from pip._internal import main then the issue is resolved.
These often comes from using pip to "update" system installed pip, and/or having multiple pip installs under user. My solution was to clean out the multiple installed pips under user, reinstall pip repo, then "pip install --user pip" as above.
See: https://github.com/pypa/pip/issues/5599 for an official complete discussion and fixes for the problem.
windows OS:
1、download this file:“https://bootstrap.pypa.io/get-pip.py”,Put it in this(E:\PythonProject\venv\Scripts’(Your virtual environment installation directory)) directory!
2、open ‘Windows PowerShell’
3、cd ‘E:\PythonProject\venv\Scripts’(Your virtual environment installation directory)
4、run cmd ‘py get-pip.py’
Please verify the directory permission for /usr/local/lib/python3.9/ and modify the permission using chown command
sudo chown -R centos:centos /usr/local/lib/python3.9/
its helps me.
Related
I have a problem when I try to use pip in any way. I'm using Ubuntu 16.04.4
I should say that I've used it already, and I never had any problem, but starting today when I use any command I always get the same error (as an example using pip --upgrade).
Traceback (most recent call last):
File "/usr/local/bin/pip", line 7, in <module>
from pip._internal import main
ImportError: No module named _internal
I have tried doing sudo apt-get remove python-pip followed by sudo apt-get install python-pip but nothing changed.
This did it for me:
python -m pip install --upgrade pip
Environment: OSX && Python installed via brew
An answer from askUbuntu works.
For pip2.7, you can at first curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py, then python2.7 get-pip.py --force-reinstall to reinstall pip.
Problem solved. Also works for python3.
This solution works for me:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --force-reinstall
or use sudo for elevated permissions (sudo python3 get-pip.py --force-reinstall).
Of course, you can also use python instead of python3 ;)
Source
Are you using python 2 or python 3? The following commands could be different!
run python3 -m pip --version to see if you have pip installed.
if yes, run python3 -m pip install --upgrade pip.
if no, run sudo apt-get install python3-pip, and do it again.
Refer to this issue list
sudo easy_install pip
works for me under Mac OS
For python3, may try sudo easy_install-3.x pip depends on the python 3.x version. Or python3 -m pip install --user --upgrade pip
This issue maybe due to common user do not have privilege to access packages py file.
1. root user can run 'pip list'
2. other common user cannot run 'pip list'
[~]$ pip list
Traceback (most recent call last):
File "/usr/bin/pip", line 7, in <module>
from pip._internal import main
ImportError: No module named pip._internal
Check pip py file privilege.
[root#]# ll /usr/lib/python2.7/site-packages/pip/
合計 24
-rw------- 1 root root 24 6月 7 16:57 __init__.py
-rw------- 1 root root 163 6月 7 16:57 __init__.pyc
-rw------- 1 root root 629 6月 7 16:57 __main__.py
-rw------- 1 root root 510 6月 7 16:57 __main__.pyc
drwx------ 8 root root 4096 6月 7 16:57 _internal
drwx------ 18 root root 4096 6月 7 16:57 _vendor
solution : root user login and run
chmod -R 755 /usr/lib/python2.7
fix this issue.
In file "/usr/local/bin/pip" change from pip._internal import main to from pip import main
For completeness, I just encountered this problem with "Ubuntu latest" ... v18.04 ... and fixed it in this way:
python3 -m pip install --upgrade pip
(Notice that it was necessary to specify python3 since this references Python 3.6.9. The python command on the same system references Python 2.7.17. Since this is apparently a system-wide installation it encountered a ["not sudo" ...] permission error, but it didn't matter because it was the wrong thing to do anyway. I was encountering the problem with pip3.)
I've seen this issue when PYTHONPATH was set to include the built-in site-packages directory. Since Python looks there automatically it is unnecessary and can be removed.
I just encountered the same problem and in my case, it turns out this is a conflict between the python installation in my virtualenv and the site-wide python (Ubuntu).
What solves it for me is to run pip in this way, to force usage of the correct python installation (in my vortualenv):
python3 -m pip install PACKAGE
instead of
pip3 install PACKAGE
I realised this when I tried to follow some of the answers here that suggest re-installing pip and the error output I got was pointing to an existing site-wide python library path although I had activated my virtualenv.
Worth trying before deleting and re-installing stuff.
For me
python -m pip uninstall pip
solved the issue. Reference
I tried the following command to solve the issue and it worked for me:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --force-reinstall
Its probably due to a version conflict, try to run this, it will remove the older pip somehow.
sudo apt remove python pip
I have fixed this error by running the following commands:
sudo apt remove python-pip
wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
It will remove the previously installed pip and reinstall it.
Thanks :)
Nothing worked for me, but only one thing:
I used sudo in front of the command and it is working fine.
I met the same error on Windows when I tried to install a package via pip3:
Traceback (most recent call last):
File "d:\anaconda\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "d:\anaconda\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "D:\Anaconda\Scripts\pip3.6.exe\__main__.py", line 5, in <module>
ModuleNotFoundError: No module named 'pip._internal'
My python is installed via Anaconda. I solved this issue by reinstalling pip via conda:
conda install pip
After that, pip returns to normal.
pip is not being installed properly on your "user", so try the following :
sudo python3 -m pip install --user --upgrade pip
The following solution solved the problem on my machine for python2.7
"$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py"
and then
"$ sudo python2.7 get-pip.py --force-reinstall"
For the current user only:
easy_install --user pip
or
python -m pip install --upgrade --user pip
The second may give /usr/bin/python: No module named pip
Even if which pip finds the module named pip.
In this case try the easy_install
Checking from pip documentation, this command worked to me:
python -m ensurepip --upgrade
I have the same problem on my virtual environment after upgrade python installation from 3.6 to 3.7 but only on vent globally pip work fine, to solve it I deactivate and delete my virtual environment after recreate again and now is fine, on venv:
deactivate
rm -rvf venv
and after recreate the virtual environment.
I use mac OS 10.11, and python 3
(On windows)
not sure why this was happening but I had my PYTHONPATH setup to point to c:\python27 where python was installed. in combination with virtualenv this produced the mentioned bug.
resolved by removing the PYTHONPATH env var all together
my solution:
first step like most other answer:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python2.7 get-pip.py --force-reinstall
second, add soft link
sudo ln -s /usr/local/bin/pip /usr/bin/pip
This command works for me.
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py --force-reinstall --user
you can remove it first, and install again ,it will be ok.
for centos:
yum remove python-pip
yum install python-pip
I fixed this problem by
sudo apt-get install python3-pip
this worked even for python2.7, amazing...
My solution is adding import pip to the script linked to the pip/pip3 commands.
Firstly, open the file (e.g. /usr/local/bin/pip) with your favorite text editor and the sudo mode. For example, I use sudo vim /usr/local/bin/pip to open the script file.
You will obtain some file as following:
import re
import sys
from pip._internal import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(main())
Afterwards, insert the statement import pip just before the from pip._internal import main then the issue is resolved.
These often comes from using pip to "update" system installed pip, and/or having multiple pip installs under user. My solution was to clean out the multiple installed pips under user, reinstall pip repo, then "pip install --user pip" as above.
See: https://github.com/pypa/pip/issues/5599 for an official complete discussion and fixes for the problem.
windows OS:
1、download this file:“https://bootstrap.pypa.io/get-pip.py”,Put it in this(E:\PythonProject\venv\Scripts’(Your virtual environment installation directory)) directory!
2、open ‘Windows PowerShell’
3、cd ‘E:\PythonProject\venv\Scripts’(Your virtual environment installation directory)
4、run cmd ‘py get-pip.py’
Please verify the directory permission for /usr/local/lib/python3.9/ and modify the permission using chown command
sudo chown -R centos:centos /usr/local/lib/python3.9/
its helps me.
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.
I have a problem when I try to use pip in any way. I'm using Ubuntu 16.04.4
I should say that I've used it already, and I never had any problem, but starting today when I use any command I always get the same error (as an example using pip --upgrade).
Traceback (most recent call last):
File "/usr/local/bin/pip", line 7, in <module>
from pip._internal import main
ImportError: No module named _internal
I have tried doing sudo apt-get remove python-pip followed by sudo apt-get install python-pip but nothing changed.
This did it for me:
python -m pip install --upgrade pip
Environment: OSX && Python installed via brew
An answer from askUbuntu works.
For pip2.7, you can at first curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py, then python2.7 get-pip.py --force-reinstall to reinstall pip.
Problem solved. Also works for python3.
This solution works for me:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --force-reinstall
or use sudo for elevated permissions (sudo python3 get-pip.py --force-reinstall).
Of course, you can also use python instead of python3 ;)
Source
Are you using python 2 or python 3? The following commands could be different!
run python3 -m pip --version to see if you have pip installed.
if yes, run python3 -m pip install --upgrade pip.
if no, run sudo apt-get install python3-pip, and do it again.
Refer to this issue list
sudo easy_install pip
works for me under Mac OS
For python3, may try sudo easy_install-3.x pip depends on the python 3.x version. Or python3 -m pip install --user --upgrade pip
This issue maybe due to common user do not have privilege to access packages py file.
1. root user can run 'pip list'
2. other common user cannot run 'pip list'
[~]$ pip list
Traceback (most recent call last):
File "/usr/bin/pip", line 7, in <module>
from pip._internal import main
ImportError: No module named pip._internal
Check pip py file privilege.
[root#]# ll /usr/lib/python2.7/site-packages/pip/
合計 24
-rw------- 1 root root 24 6月 7 16:57 __init__.py
-rw------- 1 root root 163 6月 7 16:57 __init__.pyc
-rw------- 1 root root 629 6月 7 16:57 __main__.py
-rw------- 1 root root 510 6月 7 16:57 __main__.pyc
drwx------ 8 root root 4096 6月 7 16:57 _internal
drwx------ 18 root root 4096 6月 7 16:57 _vendor
solution : root user login and run
chmod -R 755 /usr/lib/python2.7
fix this issue.
In file "/usr/local/bin/pip" change from pip._internal import main to from pip import main
For completeness, I just encountered this problem with "Ubuntu latest" ... v18.04 ... and fixed it in this way:
python3 -m pip install --upgrade pip
(Notice that it was necessary to specify python3 since this references Python 3.6.9. The python command on the same system references Python 2.7.17. Since this is apparently a system-wide installation it encountered a ["not sudo" ...] permission error, but it didn't matter because it was the wrong thing to do anyway. I was encountering the problem with pip3.)
I've seen this issue when PYTHONPATH was set to include the built-in site-packages directory. Since Python looks there automatically it is unnecessary and can be removed.
I just encountered the same problem and in my case, it turns out this is a conflict between the python installation in my virtualenv and the site-wide python (Ubuntu).
What solves it for me is to run pip in this way, to force usage of the correct python installation (in my vortualenv):
python3 -m pip install PACKAGE
instead of
pip3 install PACKAGE
I realised this when I tried to follow some of the answers here that suggest re-installing pip and the error output I got was pointing to an existing site-wide python library path although I had activated my virtualenv.
Worth trying before deleting and re-installing stuff.
For me
python -m pip uninstall pip
solved the issue. Reference
I tried the following command to solve the issue and it worked for me:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --force-reinstall
Its probably due to a version conflict, try to run this, it will remove the older pip somehow.
sudo apt remove python pip
I have fixed this error by running the following commands:
sudo apt remove python-pip
wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
It will remove the previously installed pip and reinstall it.
Thanks :)
Nothing worked for me, but only one thing:
I used sudo in front of the command and it is working fine.
I met the same error on Windows when I tried to install a package via pip3:
Traceback (most recent call last):
File "d:\anaconda\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "d:\anaconda\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "D:\Anaconda\Scripts\pip3.6.exe\__main__.py", line 5, in <module>
ModuleNotFoundError: No module named 'pip._internal'
My python is installed via Anaconda. I solved this issue by reinstalling pip via conda:
conda install pip
After that, pip returns to normal.
pip is not being installed properly on your "user", so try the following :
sudo python3 -m pip install --user --upgrade pip
The following solution solved the problem on my machine for python2.7
"$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py"
and then
"$ sudo python2.7 get-pip.py --force-reinstall"
For the current user only:
easy_install --user pip
or
python -m pip install --upgrade --user pip
The second may give /usr/bin/python: No module named pip
Even if which pip finds the module named pip.
In this case try the easy_install
Checking from pip documentation, this command worked to me:
python -m ensurepip --upgrade
I have the same problem on my virtual environment after upgrade python installation from 3.6 to 3.7 but only on vent globally pip work fine, to solve it I deactivate and delete my virtual environment after recreate again and now is fine, on venv:
deactivate
rm -rvf venv
and after recreate the virtual environment.
I use mac OS 10.11, and python 3
(On windows)
not sure why this was happening but I had my PYTHONPATH setup to point to c:\python27 where python was installed. in combination with virtualenv this produced the mentioned bug.
resolved by removing the PYTHONPATH env var all together
my solution:
first step like most other answer:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python2.7 get-pip.py --force-reinstall
second, add soft link
sudo ln -s /usr/local/bin/pip /usr/bin/pip
This command works for me.
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py --force-reinstall --user
you can remove it first, and install again ,it will be ok.
for centos:
yum remove python-pip
yum install python-pip
I fixed this problem by
sudo apt-get install python3-pip
this worked even for python2.7, amazing...
My solution is adding import pip to the script linked to the pip/pip3 commands.
Firstly, open the file (e.g. /usr/local/bin/pip) with your favorite text editor and the sudo mode. For example, I use sudo vim /usr/local/bin/pip to open the script file.
You will obtain some file as following:
import re
import sys
from pip._internal import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(main())
Afterwards, insert the statement import pip just before the from pip._internal import main then the issue is resolved.
These often comes from using pip to "update" system installed pip, and/or having multiple pip installs under user. My solution was to clean out the multiple installed pips under user, reinstall pip repo, then "pip install --user pip" as above.
See: https://github.com/pypa/pip/issues/5599 for an official complete discussion and fixes for the problem.
windows OS:
1、download this file:“https://bootstrap.pypa.io/get-pip.py”,Put it in this(E:\PythonProject\venv\Scripts’(Your virtual environment installation directory)) directory!
2、open ‘Windows PowerShell’
3、cd ‘E:\PythonProject\venv\Scripts’(Your virtual environment installation directory)
4、run cmd ‘py get-pip.py’
Please verify the directory permission for /usr/local/lib/python3.9/ and modify the permission using chown command
sudo chown -R centos:centos /usr/local/lib/python3.9/
its helps me.
I downloaded pip and ran python setup.py install and everything worked just fine. The very next step in the tutorial is to run pip install <lib you want> but before it even tries to find anything online I get an error "bash: pip: command not found".
This is on Mac OS X. I'm assuming there's some kind of path setting that was not set correctly when I ran setup.py. How can I investigate further? What do I need to check to get a better idea of the exact cause of the problem?
EDIT: I also tried installing Python 2.7 for Mac in the hopes that the friendly install process would do any housekeeping like editing PATH and whatever else needs to happen for everything to work according to the tutorials, but this didn't work. After installing, running 'python' still ran Python 2.6 and PATH was not updated.
Why not just do sudo easy_install pip or if this is for python 2.6 sudo easy_install-2.6 pip?
This installs pip using the default python package installer system and saves you the hassle of manual set-up all at the same time.
This will allow you to then run the pip command for python package installation as it will be installed with the system python. I also recommend once you have pip using the virtualenv package and pattern. :)
2020 Update:
For current Debian/Ubuntu, use
apt-get install python3-pip
to install pip3.
Old 2013 answer (easy_install is now deprecated):
Use setuptools to install pip: sudo easy_install pip
(I know the above part of my answer is redundant with klobucar's, but I can't add comments yet), so here's an answer with a solution to sudo: easy_install: command not found on Debian/Ubuntu: sudo apt-get install python-setuptools
Also, for python3, use easy_install3 and python3-setuptools.
For Python 3, use apt-get install python3-pip.
First of all: try pip3 instead of pip. Example:
pip3 --version
pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)
pip3 should be installed automatically together with Python3.x. The documentation hasn't been updated, so simply replace pip by pip3 in the instructions, when installing Flask for example.
Now, if this doesn't work, you might have to install pip separately.
Update: A more reliable modern way to access the right pip install for the right python install is to use the syntax python -m pip.
Original Answer
pip would install itself into the bin of your python installation location. It also should create a symlink to some more common location like /usr/local/bin/pip
You can either edit your ~/.profile and update your PATH to include /Library/Frameworks/Python.framework/Versions/2.6/bin, or you could create a symlink to it in a place that you know is in your path.
If you do: echo $PATH, you should see the paths currently being searched. If /usr/local/bin is in your PATH, you can do:
ln -s /Library/Frameworks/Python.framework/Versions/2.6/bin/pip /usr/local/bin
I would opt for adding the python bin to your $PATH variable.
I encountered this problem having downloaded python 3.x.x and trying to install awscli - pip: command not found.
Whilst following the instructions for downloading the AWS client, I changed
pip install awscli
to
pip3 install awscli
which ran the correct version.
I've made an alias on my machine to run python3 whilst typing python, which would normally run the system version 2.7. I'm not sure this is a good idea now. I think I'll just type in the commands as they intended them to be.
Check out How to Install Pip article for more information.
As of 2019,
Download get-pip.py provided by https://pip.pypa.io using the following command:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Run get-pip.py using the following command:
sudo python get-pip.py
After you done installing, run this command to check if pip is installed.
pip --version
Remove get-pip.py file after installing pip.
rm get-pip.py
Install Python latest version as given here
It has many download links like numpy and scipy
Then go to terminal and enter following command:-
sudo easy_install pip
For Python install packages check this
Requirements for Installing Packages
This section describes the steps to follow before installing other Python packages.
Install pip, setuptools, and wheel 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 OS X:
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 Installing pip/setuptools/wheel
with Linux Package Managers
Otherwise:
Securely Download get-pip.py 1
Run python get-pip.py. 2 This will install or upgrade pip.
Additionally, it will install setuptools and wheel if they’re not
installed already.
I spent ages going through all the answers on this page but found the one that worked for me in the comments of the OP question by s-walsh
The answer is to use pip3:
$ pip3 install <name-of-install>
Installing using apt-get installs a system wide pip, not just a local one for your user. Try this command to get pip running on your system ...
$ sudo apt-get install python-pip python-dev build-essential
Then pip will be installed without any issues and you will be able to use "sudo pip...".
Most of the methods to install PIP are deprecated. Here is the latest (2019) solution. Please download get-pip script
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Run the script
sudo python get-pip.py
Latest update 2021.
In Ubuntu 20 64bit works perfectly
Installation of python3
sudo apt install python3
Pip Installation
sudo apt install python3-pip
Add following alias in $HOME/.bash_aliases in some cases file may be hidden.
alias pip="/usr/bin/python3 -m pip "
Refresh current terminal session.
. ~/.profile
check pip usage: pip
Install a package: pip install {{package_name}}
extra info
to get Home path
echo $HOME
you will get your home path.
To solve:
Add this line to ~/.bash_profile:
export PATH="/usr/local/bin:$PATH"
In a terminal window, run
source ~/.bash_profile
It might be the root permission. I tried exit root login, and use
sudo su -l root
pip <command>
install Homebrew, open Terminal or your favorite OSX terminal emulator and run
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
insert the Homebrew directory at the top of your PATH environment variable. You can do this by adding the following line at the bottom of your ~/.profile file
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
Now, we can install Python 2.7:
$ brew install python
Get pip repository:
$ git clone https://github.com/pypa/pip
install pip:
$sudo easy_install pip
python install it by default but if not install you can install it manual use following cmd (for linux only )
for python3 :
sudo apt install python3-pip
for python2
sudo apt install python-pip
hope its help.
If you are running Python 3.5, run the following terminal command:
sudo pip3 install -U nltk
Any other pip commands in terminal would be similar:
pip3 install --upgrade pip
sudo pip3 install -U numpy ::
It solved my problem by using
sudo easy_install pip
Solved this by upgrading python 3 brew upgrade python:
Now i can just do:
pip3 install <package>
==> python
Python has been installed as
/usr/local/bin/python3
Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have
Based on this stackoverflow answer and some of the answers on this thread, I have created an alias in the rc file:
alias pip="python3 -m pip"
There seem to be many different answers to this question but this seems to be the best-practice approach.
Avoiding sudo:
python <(curl https://bootstrap.pypa.io/get-pip.py) --user
echo 'export "PATH=$HOME/Library/Python/2.7/bin:$PATH"' >> ~/.bash_profile
From:
http://www.pip-command-not-found.com
CentOS 7 users can just use:
yum install python-pip
Also recommend using virtualenv if you're using pip. It can be added in the same way:
yum install python-virtualenv
assuming you have internet see:
https://pip.pypa.io/en/stable/installing/
basically run:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
and
python get-pip.py
Try using this. Instead of zmq, we can use any package instead of zmq.
sudo apt-get install python3-pip
sudo apt-get update
python3 -m pip install zmq
I was was not able to install this zmq package in my docker image because of the same issue i was getting. So tried this as another way to install and it worked fine for me.
To overcome the issue bash: pip: command not found in Mac
Found two versions on Mac 1 is 2.7 and the other is 3.7
when I say sudo easy_install pip, pip got installed under 2.7
when I say sudo easy_install-3.7 pip, pip got installed under 3.7
But, whenever I would require to do pip install , I wanted to install the package under python3.7, so I have set an alias (alias pip=pip3) in .bash_profile.
so now, whenever I do pip install <package_name>, it gets installed under python3.7
(Context: My OS is Amazon linux using AWS. It seems similar to RedHat but it's stripped down a bit, it seems.)
Exit the shell, then open a new shell. The pip command now works.
That's what solved the problem at this location.
You might want to know as well: The pip commands to install software then needed to be written like this example (jupyter for example) to work correctly on my system:
pip install jupyter --user
Specifically, note the lack of sudo, and the presence of --user
Would be real nice if pip docs had said anything about all this, but that would take typing in more characters I guess.
Not sure why this wasnt mentioned before, but the only thing that worked for me (on my NVIDIA Xavier) was:
sudo apt-get install python3-pip
(or sudo apt-get install python-pip for python 2)
apt -y -qq install python3 python3-pip
ln -s /usr/bin/python3 /usr/bin/python
ln -s /usr/bin/pip3 /usr/bin/pip
What I did to overcome this was sudo apt install python-pip.
It turned out my virtual machine did not have pip installed yet. It's conceivable that other people could have this scenario too.
The updated command for installing pip3 is :
sudo apt-get install python3-pip
The problem seems that your python version and the library yoıu want to install is not matching versionally. Ex: If Django is Django3 and your python version is 2.7, you may get this error.
"After installing is running 'python' still ran Python 2.6 and PATH was not updated."
1- Install latest version of Python
2- Change your PATH manually as python38 and compare them.
3- Try to reinstall.
I solved this problem as replacing PATH manually with the latest version of Python.
As for Windows: ;C:\python38\Scripts
I am using Django 1.3.7 and python 2.7.6 on windows7
I got an error when I executing my manage.py in this line of code
import shutil, sys, virtualenv, subprocess
amd running it, I got this error
C:\Django-Proj\>python manage.py update_ve
Traceback (most recent call last):
File "manage.py", line 4, in <module>
import shutil, sys, virtualenv, subprocess
ImportError: No module named virtualenv
Does anyone have an Idea about my case?
Install virtualenv using pip install virtualenv.
If you have it already installed, try reinstalling it by removing it with pip uninstall virtualenv and then reinstalling it.
Good Luck.
I had to install virtualenv with the -H flag to set HOME variable to target user's home dir.
sudo -H pip install virtualenv
I think the problem is you need sudo to globally install virtualenv.
> pip install virtualenv
Could not find an activated virtualenv (required).
> sudo pip install virtualenv
Downloading/unpacking virtualenv
...
But this creates files readable only by root (depending on the umask).
In this case, uninstalling/reinstalling may not always help.
You can check with ls -la /usr/local/lib/python2.7/dist-packages/virtualenv.py (replacing 2.7 with whatever version you have or are targeting).
My solution was simply:
sudo chmod -R o+rX /usr/local/lib/python2.7
Use pip3 instead of pip. I had the same issue and pip3 worked for me.
$ pip3 install virtualenv
$ virtualenv venv --python=python3
Try
python3 -m pip uninstall virtualenv
python3 -m pip install virtualenv
I just ran into this same problem. I had to pip uninstall virtualenv as a user with admin rights, then pip install virtualenv as a normal user. I think it's some kind of permissions issue if you installed virtualenv under admin rights.
>virtualenv
ImportError: No module named 'virtualenv'
>pip uninstall virtualenv
PermissionError: [Errno 13] Permission denied:
>sudo pip uninstall virtualenv
Successfully uninstalled virtualenv-15.1.0
>pip install virtualenv
Collecting virtualenv
>virtualenv
Options:
Bingo!
I had the same problem when I created my virtualenv via pycharm and installed requirements with pycharm.
After trail and error , I found that installed requirements are not taken into account by the virtualenv.
The solution is to reinstall all requirements once you have activated your virtualenv:
venv\scripts\activate
python -m pip install -r YourRequirements.txt
Next time I'd better create my virtualenv directly with command line
Got this error when using the ansible pip module automating some pip installs on my localhost.
fatal: [localhost]: FAILED! => {"changed": false, "cmd": ["/opt/bin/virtualenv", "--system-site-packages", "-p/usr/bin/python3", "/opt/venv/myenv"], "msg": "\n:stderr: /usr/bin/python3: No module named virtualenv\n"}
Uninstalling virtualenv python3 -m pip uninstall virtualenv did show virtualenv was installed here /home/ubuntu/.local/bin/virtualenv.
In the ansible task specify the virtualenv_command:
- name: install requirements file
pip:
virtualenv_command: "/home/{{whoami.stdout}}/.local/bin/virtualenv"
virtualenv: "/home/{{whoami.stdout}}/.venv/{{item.env.virtualenv}}"
requirements: "/home/{{whoami.stdout}}/git/{{item.env.requirements_txt}}"
virtualenv_site_packages: yes
when: req_stat.stat.exists
For mac os the issue was with virtualenv. This is because the folder virtualenv did not exist.
This worked well
python3 -m venv env