Daniel
Daniel

Reputation: 59

How to make pip work?

I cant figure out how to get pip to work for me. I have python 3.5.1 and I run

import pip
pip.main(['install', 'psutil'])

and get an error saying "AttributeError: module 'pip' has no attribute 'main'".

Im just wondering what I need to do for pip to work

EDIT My code was named pip.py so I renamed it now when it runs I get this

Collecting 

psutil
  Using cached psutil-4.0.0-cp35-none-win32.whl
Installing collected packages: psutil
Exception:
Traceback (most recent call last):
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\pip\basecommand.py", line 211, in main
    status = self.run(options, args)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\pip\commands\install.py", line 311, in run
    root=options.root_path,
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\pip\req\req_set.py", line 646, in install
    **kwargs
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\pip\req\req_install.py", line 803, in install
    self.move_wheel_files(self.source_dir, root=root)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\pip\req\req_install.py", line 998, in move_wheel_files
    isolated=self.isolated,
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\pip\wheel.py", line 339, in move_wheel_files
    clobber(source, lib_dir, True)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\pip\wheel.py", line 310, in clobber
    ensure_dir(destdir)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\pip\utils\__init__.py", line 71, in ensure_dir
    os.makedirs(path)
  File "C:\Program Files (x86)\Python35-32\lib\os.py", line 241, in makedirs
    mkdir(name, mode)
PermissionError: [WinError 5] Access is denied: 'C:\\Program Files (x86)\\Python35-32\\Lib\\site-packages\\psutil'
You are using pip version 7.1.2, however version 8.0.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

Upvotes: 0

Views: 740

Answers (2)

ShadowRanger
ShadowRanger

Reputation: 155363

The PermissionError makes this fairly obvious. C:\Program Files (x86) (and all sub-directories) have permissions set such that only Administrators can write to them (for security reasons).

You need to run your script from an administrative command prompt, or otherwise run it with admin privileges. For example, in the Start Menu search box, type cmd.exe, right click the result, and select "Run as administrator". Running your script from within the elevated prompt should install normally.

Upvotes: 0

Padraic Cunningham
Padraic Cunningham

Reputation: 180401

You called your script pip.py or you have a file in your path that is called pip.py so you are importing from that not the pip module. Use pip.__file__ to see where the file is and either rename or remove it, making sure to remove any .pyc file with the same name.

Upvotes: 2

Related Questions