pip is not installing pyowm correctly for some rea

2019-09-12 09:36发布

问题:

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?

回答1:

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!



回答2:

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 pip