Unable to install pip and packages [duplicate] - python

This question already has answers here:
ImportError: cannot import name main when running pip --version command in windows7 32 bit
(16 answers)
Closed 2 years ago.
I'm using python 3.6. Pip is installed along with python. Seems like pip isn't showing up. Tried various solutions available here nothing worked. Please help me solve this.
Verifications done:
Path is set as C:\Program Files\Python36\Scripts
Added host entries for all 3
PIP error:
C:\Users\>pip
Traceback (most recent call last):
File "c:\program files\python36\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\program files\python36\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Program Files\Python36\Scripts\pip.exe\__main__.py", line 5, in <module>
ImportError: cannot import name 'main'
Tried solutions:
pip install --trusted-host pypi.python.org --trusted-host pypi.org --trusted-host files.pythonhosted.org {package name}
C:\Users\>pip
Traceback (most recent call last):
File "c:\program files\python36\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\program files\python36\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Program Files\Python36\Scripts\pip.exe\__main__.py", line 5, in <module>
ImportError: cannot import name 'main'
C:\Users>python3 -m pip uninstall pip setuptools
'python3' is not recognized as an internal or external command,
operable program or batch file.
C:\Users>python
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> python3 -m pip uninstall pip setuptools
File "<stdin>", line 1
python3 -m pip uninstall pip setuptools
^
SyntaxError: invalid syntax
>>> python3 -m pip uninstall pip setuptools
File "<stdin>", line 1
python3 -m pip uninstall pip setuptools
^
SyntaxError: invalid syntax
>>> pip install --trusted-host pypi.python.org --trusted-host pypi.org --trusted-host files.pythonhosted.org {package name}
File "<stdin>", line 1
pip install --trusted-host pypi.python.org --trusted-host pypi.org --trusted-host files.pythonhosted.org {package name}
^
SyntaxError: invalid syntax
>>>
Using below version
C:\Users\>python
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

Try using
pip2
For python 2. And
pip3
For python 3
And do it from an admin cmd line.

Check you have added paths to the these directories (if you are using python3.x versions) -
C:\Users\tojose\AppData\Local\Programs\Python\Python3.x and for pip
C:\Users\tojose\AppData\Local\Programs\Python\Python3.x\Scripts as pip*.exe's are
stored here.

Try to use the full path for both pip and the package you want to install.
Example (for Python 3.6):
C:\Python36\Scripts\pip install C:\Python36\requests-2.18.4-py2.py3-none-any.whl

On Windows 10, I had the same problem. PIP 19 was already installed in my system but wasn't showing up. The error was No Module Found.
python -m pip uninstall pip
python -m pip install pip==9.0.3
Downgrading pip to 9.0.3 worked fine for me.
I already answered it HERE

I had the same issue and have tried several commands without a result. I just simply upgraded my pip version from 19.10 to version 20.3.3 and now it's working fine.
python -m pip install --upgrade pip
(for windows)
Note: you are applying the pip command inside the Python REPL, which is wrong.
By using exit() function come out from Python and write like this.
In my case I have already installed a new version.

Related

Python 3: ModuleNotFoundError: No module named 'pandas.util' (raspberry pi)

Am having issues importing pandas on python3 on my raspberry pi. Whatever I try, I get the following error:
pi#raspberrypi:/ $ python3
Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.7/dist-packages/pandas/__init__.py", line 22, in <module>
from pandas.compat import (
File "/usr/local/lib/python3.7/dist-packages/pandas/compat/__init__.py", line 15, in <module>
from pandas.compat.numpy import (
File "/usr/local/lib/python3.7/dist-packages/pandas/compat/numpy/__init__.py", line 7, in <module>
from pandas.util.version import Version
ModuleNotFoundError: No module named 'pandas.util'
It works fine on Python 2.7. I am getting errors with Python 3.7.3.
I searched Google and tried everything in the following post:
ImportError: No module named pandas
Some of the things I’ve tried are below - none have helped - I still get the error.
pip3 install pandas-util
pip3 install pandas.util
sudo apt-get install python3-wheel
sudo python3 -m pip install pandas
pip3 install pandas --upgrade
I've also tried uninstalling and reinstalling numpy and pandas - still get this error just with a basic import statement.
Any help would be appreciated as this is driving me insane!!
Cheers!
Try with
python3 -m pip install --force-reinstall pandas
This will ensure two things:
it will use the pip executable that belongs to the used Python executable, so that there is no accidental installation by another pip.
it will properly re-install Pandas.
Note that it doesn't re-download the Pandas package (it will use a cached version) if the version on PyPI hasn't changed between now and the previous installation. If that is a potential problem (incorrect cached file, for example), add the option --no-cache-dir to pip install.

matplotlib works with default python but not python3.5 on debian

I have this issue. I think it's best described when I show you my bash commands that I used to produce the problem. See here:
josch#oogway:~$ python
Python 2.7.9 (default, Jun 29 2016, 13:08:31)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> #works
josch#oogway:~$ python3.5
Python 3.5.0 (default, Apr 26 2017, 21:03:53)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'matplotlib'
>>> #what??
Matplotlib was installed by:
sudo apt-get install python-matplotlib
The "default" python came with my OS installation, python3.5 was downloaded and then compiled/installed from source.
Can anyone help? Tried to solve it myselve for 2 hours now but google can't find answer
Edit: I'm trying to install a "second pip" that works with my second installation of Python, which is Python3.5. My default-Python that is managed by the OS is Python 2.7.9. Now, as suggested I did:
joschua#oogway:~/Downloads$ wget https://bootstrap.pypa.io/get-pip.py
and then:
python3.5 get-pip.py
which gave me:
joschua#oogway:~/Downloads$ python3.5 get-pip.py
Traceback (most recent call last):
File "get-pip.py", line 20061, in <module>
main()
File "get-pip.py", line 194, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 82, in bootstrap
import pip
zipimport.ZipImportError: can't decompress data; zlib not available
Try installing pip3 with:
sudo apt-get install python3-pip
and then try installing matplotlib with:
sudo pip3 install matplotlib
I actually could solve the problem now.
See this link for a reasonable description on how to run two different versions of python on the same system (and as #Pierre de Buyl suggested) use two different pip versions on the same system
https://www.linkedin.com/pulse/20140815081557-89781742-how-to-install-and-use-python-with-different-versions-on-same-linux-machine
So, you installed python3.5 from source. What version of Debian are you using? (I suppose Jessie).
If you want to install packages for this Python interpreter, you must have a pip that actually uses it. Two solutions:
It is installed. If so,
python3.5 -m pip
will work and you can install packages with
python3.5 -m pip install matplotlib
or
python3.5 -m pip install --user matplotlib
It is not installed. You must install it following the instructions at https://packaging.python.org/installing/#requirements-for-installing-packages
apt-get will not install the appropriate pip for your needs. It will only install a pip that is related to the python3 (3.4 for jessie I believe) that is also in the apt-get system.
EDIT: in light of the update, you need also to re-compile python3.5 with zip enabled.

pip is not installing pyowm correctly for some reason

I am trying to install this package pyowm via pip. but it is not working for some reason. It is a ubuntu 16 VM. I have used pip to install other packages and it has all worked fine before so I am not sure why this one is having problems.
ubuntu#ip-172-31-22-187:~/.cache/pip$ pip install pyowm
Collecting pyowm
Installing collected packages: pyowm
Exception:
Traceback (most recent call last):
File "/home/ubuntu/.local/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/home/ubuntu/.local/lib/python2.7/site-packages/pip/commands/install.py", line 342, in run
prefix=options.prefix_path,
File "/home/ubuntu/.local/lib/python2.7/site-packages/pip/req/req_set.py", line 784, in install
**kwargs
File "/home/ubuntu/.local/lib/python2.7/site-packages/pip/req/req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/home/ubuntu/.local/lib/python2.7/site-packages/pip/req/req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "/home/ubuntu/.local/lib/python2.7/site-packages/pip/wheel.py", line 345, in move_wheel_files
clobber(source, lib_dir, True)
File "/home/ubuntu/.local/lib/python2.7/site-packages/pip/wheel.py", line 316, in clobber
ensure_dir(destdir)
File "/home/ubuntu/.local/lib/python2.7/site-packages/pip/utils/__init__.py", line 83, in ensure_dir
os.makedirs(path)
File "/usr/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/pyowm-2.5.0.dist-info'
As you can see it thinks I don't have the right permission. So I did this instead:
ubuntu#ip-172-31-22-187:/usr/local/lib/python2.7/dist-packages$ sudo -H pip install pyowm
Collecting pyowm
Installing collected packages: pyowm
Successfully installed pyowm-2.5.0
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
But when I try to call it this happens:
ubuntu#ip-172-31-22-187:~/.cache/pip$ python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyowm
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'pyowm'
>>>
So now I am very confused. pip says it did the job, but pyowm doesn't show up? The result is same for python 2.7 or 3.5.
And I can see that the pyowm stuff is there:
ubuntu#ip-172-31-22-187:/usr/local/lib/python2.7/dist-packages/pyowm$ pwd
/usr/local/lib/python2.7/dist-packages/pyowm
ubuntu#ip-172-31-22-187:/usr/local/lib/python2.7/dist-packages/pyowm$ ls
abstractions caches commons constants.py constants.pyc exceptions __init__.py __init__.pyc utils webapi25
And I did try to upgrade pip as well but this is what I got:
ubuntu#ip-172-31-22-187:/usr/local/lib$ pip install --upgrade pip
Requirement already up-to-date: pip in /home/ubuntu/.local/lib/python2.7/site-packages
ubuntu#ip-172-31-22-187:/usr/local/lib/python2.7/dist-packages/pyowm$ pip -V
pip 9.0.1 from /home/ubuntu/.local/lib/python2.7/site-packages (python 2.7)
So I am very very confused. I am at version 9.0.1, but why does the cmd output earlier show I am on version 8? Why do I suddenly need to sudo to install pyowm when yesterday I installed reportLab without needing sudo? Why after installing it with sudo I can't call on pyowm?
A very valid question!
I assume you're trying to install pyowm for Python 3. If so you need to use pip3. Ubuntu comes with Python 2.7 and 3.5.
For Python 2.*: use pip install pyowm.
For Python 3.*: use pip3 install pyowm.
pip3 does not come with linux by default, use sudo apt-get install pip3 to get it.
The permission problem is most likely caused from the fact that you may not be root, not to worry! You can use the command sudo to give you root permissions for the following command.
So to install pyowm, you'd use: sudo pip3 install pyowm. Take special note of the sudo.
As a bit of background, I tried the commands you used and got almost exactly the same errors. When I ran this it worked fine :)
Hope this helps!
Hi I know it's been 2 years, but hopefully this answer can help somebody.
You installed pyowm with sudo, and then tried to access it with your current user's installation of python3 instead of root user's python3.
If you do:
sudo pip3 install pyowm
Then to access your installed library you need to open the right python3 interpreter:
sudo python3 # this interpreter belongs to root user, and has pyowm installed.
AND NOT:
python3 # this interpreter belongs to a normal user, it doesn't have pyowm installed.
And finally, if you ever have permission issues with any directory, you can always give yourself permission if you have root user access.
Just do:
sudo chmod 777 <path_to_directory_where_you_want_permissions>
Now 777 is bad practice, but it's ok when you're messing around on your own computer. If you're on a deployed server or a work machine you'll want to find the right combination, may be 665 or 666.
In your case the command would be:
sudo chmod 777 /usr/local/lib/python2.7/dist-packages/
Also notice when you call pip instead of pip3 it invokes python2.7 and not python3! So if want python3, use pip3. This is linux specific. Most linux distributions follow this convention for python installations. On Windows I usually see just "python" mapped to the latest installation of python :)

Python importing modules in CMD

Hello thanks for looking.
i am trying to import third party modules but having a hard time.
I have already done the edit to the environment variable and i get python to show up in cmd but I can not find the correct syntax to do the install.
based on the python org site i should use python -m pip install SomePackage
i have also read that i should use pip install SomePackage
I have tried both and have not had success. I am in windows 10 below is the command prompt of my attempts.
C:\Users\T****J>python
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> -m pip install send2trash
File "<stdin>", line 1
-m pip install send2trash
^
SyntaxError: invalid syntax
>>> pip install send2trash
File "<stdin>", line 1
pip install send2trash
^
SyntaxError: invalid syntax
>>> python pip install send2trash
File "<stdin>", line 1
python pip install send2trash
^
SyntaxError: invalid syntax
>>> python -m pip install requests
File "<stdin>", line 1
python -m pip install requests
^
SyntaxError: invalid syntax
>>>
thanks again. searched the best i could and maybe i am missing something easy. I am new at this .
you are trying to give command line arguments within the interpreter...
If PIP is installed, you don't need to invoke the interpreter at all. Simply call:
C:\Users\T****J>pip install send2trash
from the command prompt.
otherwise, if you are using the pip module, you need to pass the command line arguments to the command line not to the interpreter...
C:\Users\T****J>python -m pip install send2trash
pip is a program itself, similar to how npm, bundler or nuget works.
What you are currently doing is firing up the Python interpreter, and writing the call to pip from there, it doesn't work like that.
What you're looking to do is to install a package with pip, like this:
C:\Users\T****J>pip install send2trash
and after that's done you can open the interpreter again and import the module like this:
C:\Users\T****J>python
>>> import send2trash
I strongly suggest, however, that you do a bit of research into virtualenv and how to use it, it will make your life easier on the long run

'pip3 --version' failing with a SyntaxError

This all began when I set out to install the Requests library for Python 3 (I'm running on OSX Mavericks with Python 2.7.5 (installed by brew install python) and 3.4.2 (installed by brew install python3). When I run pip3 --version (or anything related to the pip3 command) I see this:
$ pip3 --version
Traceback (most recent call last):
File "/usr/local/bin/pip3", line 7, in <module>
from pip import main
File "/usr/local/lib/python3.4/site-packages/pip/__init__.py", line 11, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "/usr/local/lib/python3.4/site-packages/pip/vcs/mercurial.py", line 9, in <module>
from pip.download import path_to_url
File "/usr/local/lib/python3.4/site-packages/pip/download.py", line 22, in <module>
from pip._vendor import requests, six
File "/usr/local/lib/python3.4/site-packages/pip/_vendor/requests/__init__.py", line 53, in <module>
from .packages.urllib3.contrib import pyopenssl
File "/usr/local/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/contrib/pyopenssl.py", line 49, in <module>
from ndg.httpsclient.ssl_peer_verification import SUBJ_ALT_NAME_SUPPORT
File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/ndg/httpsclient/ssl_peer_verification.py", line 17
except ImportError, e:
^
SyntaxError: invalid syntax
When I run the Python 2.7.5 version I see this:
$ pip --version
pip 1.5.6 from /Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg (python 2.7)
Just for sanity purposes Here is what when I see when I enter the interactive interpreters:
$ python3
Python 3.4.2 (default, Oct 19 2014, 17:52:17)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.51)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
$ python
Python 2.7.5 (default, Mar 9 2014, 22:15:05)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
A lot of the other answers related to updating pip3 suggest that I update pip3 with this commend pip3 install --upgrade pip which gives the same error, or I use easy_install -U pip but because of how brew sets up the Pythons, it only updates the Python 2.7.5 version (there is no easy_install3). Any ideas?
The root problem is that you somehow got a Python 2.x-only package installed into your 3.x site-packages.
Underlying that, you've actually got two different Python 2.7 installations (Apple's and Homebrew's) crossed with each other, which may have something to do with how you got a 2.7 package into 3.x as well…
Anyway, the reason this is breaking pip is that pip has various optional dependencies that it tries to import if present, and some of them do the same, and so on, and ultimately, starting up pip is importing the ndg-httpsclient package.
I'm not sure how you got that package. A standard Homebrew 3.x looks in two extra site-packages directories (fire up python3 then import sys; print(sys.path) to see all of the places it looks, both stdlib and site) beyond the one that pip3 installs into.
In this case, you've somehow installed the 2.x version of ndg-httpsclient into /usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/‌​python3.4/site-packages.
Since you didn't install it with pip—and, more to the point, since you can't run pip in the first place—you can't just pip uninstall it. So:
rm -rf /usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/‌​python3.4/site-packages/ndg*
This could break some other packages that depend on it. Once you get things working, you can use pip3 list to see all the site packages you've installed and test them out. If you want to be paranoid, do something like this:
$ pip3 list > mypackages
$ rm -rf <each site-package directory>
$ brew uninstall python3
$ brew install python3
$ pip3 install -r mypackages
You might want to similarly clean up your Homebrew 2.7 (or just scrap it and only use Apple's—especially since I'm pretty sure you're running Apple's anyway), and the site-packages for the Apple 2.7 (but not Apple's Python itself, of course, because you can't uninstall that).

Categories