How to make pip work? - python

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.

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.

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.

Related

I cannot install sklearn, numpy, and scipy on Windows 10 command Prompt to use on Python 3.6

I have Python 3.6 correctly installed and have been working on Eclipse. But I cannot use the libraries. Every time I import them I get an error message:
Traceback (most recent call last):
File "C:\Users\gilbe\eclipse-workspace\python3.6\BeginnerFiles\IrisDataSet", line 1, in <module>
from sklearn import datasets
ModuleNotFoundError: No module named 'sklearn'`
When I tried installing sklearn, numpy, and scipy, I type in the following into Windows Command Prompt:
"pip install numpy", "pip install scipy", or "pip install sklearn".
However, I get an error message every time. For example:
C:\Program Files (x86)\Python36-32\Scripts>pip install sklearn
Collecting sklearn
Using cached https://files.pythonhosted.org/packages/1e/7a/dbb3be0ce9bd5c8b7e3d87328e79063f8b263b2b1bfa4774cb1147bfcd3f/sklearn-0.0.tar.gz
Collecting scikit-learn (from sklearn)
Using cached https://files.pythonhosted.org/packages/87/b7/0e7f5c0cf765cf4e1924c068e7b2e1708c93ebffde9302a57ea8f26619e9/scikit_learn-0.19.1-cp36-cp36m-win32.whl
Installing collected packages: scikit-learn, sklearn
Exception:
Traceback (most recent call last):
File "c:\program files (x86)\python36-32\lib\site-packages\pip\basecommand.py", line 215, in main
status = self.run(options, args)
File "c:\program files (x86)\python36-32\lib\site-packages\pip\commands\install.py", line 342, in run
prefix=options.prefix_path,
File "c:\program files (x86)\python36-32\lib\site-packages\pip\req\req_set.py", line 784, in install
**kwargs
File "c:\program files (x86)\python36-32\lib\site-packages\pip\req\req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "c:\program files (x86)\python36-32\lib\site-packages\pip\req\req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "c:\program files (x86)\python36-32\lib\site-packages\pip\wheel.py", line 345, in move_wheel_files
clobber(source, lib_dir, True)
File "c:\program files (x86)\python36-32\lib\site-packages\pip\wheel.py", line 316, in clobber
ensure_dir(destdir)
File "c:\program files (x86)\python36-32\lib\site-packages\pip\utils\__init__.py", line 83, in ensure_dir
os.makedirs(path)
File "c:\program files (x86)\python36-32\lib\os.py", line 220, in makedirs
mkdir(name, mode)
PermissionError: [WinError 5] Access is denied: 'c:\\program files (x86)\\python36-32\\Lib\\site-packages\\scikit_learn-0.19.1.dist-info'
You are using pip version 9.0.3, however version 10.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
Further, when I try to upgrade the pip command using the suggested command above, I also get an error message:
C:\Program Files (x86)\Python36-32\Scripts>python -m pip install --upgrade pip
Collecting pip
Using cached https://files.pythonhosted.org/packages/0f/74/ecd13431bcc456ed390b44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl
Installing collected packages: pip
Found existing installation: pip 9.0.1
Uninstalling pip-9.0.1:
Exception:
Traceback (most recent call last):
File "C:\Program Files\Inkscape\python\lib\site-packages\pip\basecommand.py", line 215, in main
status = self.run(options, args)
File "C:\Program Files\Inkscape\python\lib\site-packages\pip\commands\install.py", line 342, in run
prefix=options.prefix_path,
File "C:\Program Files\Inkscape\python\lib\site-packages\pip\req\req_set.py", line 778, in install
requirement.uninstall(auto_confirm=True)
File "C:\Program Files\Inkscape\python\lib\site-packages\pip\req\req_install.py", line 754, in uninstall
paths_to_remove.remove(auto_confirm)
File "C:\Program Files\Inkscape\python\lib\site-packages\pip\req\req_uninstall.py", line 115, in remove
renames(path, new_path)
File "C:\Program Files\Inkscape\python\lib\site-packages\pip\utils\__init__.py", line 267, in renames
shutil.move(old, new)
File "C:\Program Files\Inkscape\python\lib\shutil.py", line 303, in move
os.unlink(src)
WindowsError: [Error 5] Access is denied: 'c:\\program files\\inkscape\\python\\lib\\site-packages\\pip-9.0.1.dist-info\\description.rst'
You are using pip version 9.0.1, however version 10.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
My real question here is how do I fix these issues, and install these libraries correctly, I have spent a whole day trying to fix this in different ways, including: installing the libraries from inside Eclipse, through Window>Preferences>Interpreter>Python Interpreter>Install with pip
, Uninstalling and Reinstalling Python, attempting to use the easy_install <package> command.
Please help.
right click on the windows button on bottom left of your screen.
Then go to "Windows PowerShell(Admin).
There you try your pip installs. It will definitely work. I think you don't have the admin access that is why you are seeing.
PermissionError: [WinError 5] Access is denied
Just open the cmd with admin as user.Hope this helps.

Pip won't install anything or upgrade and can't be removed

I'm on Python 3.6 and trying to use py -m pip install discord.py to install the discord package to write a discord bot. However, that command works most of the way until it says Rolling back uninstall of pip and then it crashes like so:
Exception:
Traceback (most recent call last):
File "C:\Program Files\Python36\lib\site-packages\pip\basecommand.py", line 211, in main
status = self.run(options, args)
File "C:\Program Files\Python36\lib\site-packages\pip\commands\install.py", line 311, in run
root=options.root_path,
File "C:\Program Files\Python36\lib\site-packages\pip\req\req_set.py", line 646, in install
**kwargs
File "C:\Program Files\Python36\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\Python36\lib\site-packages\pip\req\req_install.py", line 998, in move_wheel_files
isolated=self.isolated,
File "C:\Program Files\Python36\lib\site-packages\pip\wheel.py", line 449, in move_wheel_files
generated.extend(maker.make(spec))
File "C:\Program Files\Python36\lib\site-packages\pip_vendor\distlib\scripts.py", line 353, in make
self._make_script(entry, filenames, options=options)
File "C:\Program Files\Python36\lib\site-packages\pip_vendor\distlib\scripts.py", line 257, in _make_script
self._write_script(scriptnames, shebang, script, filenames, ext)
File "C:\Program Files\Python36\lib\site-packages\pip_vendor\distlib\scripts.py", line 193, in _write_script
launcher = self._get_launcher('t')
File "C:\Program Files\Python36\lib\site-packages\pip_vendor\distlib\scripts.py", line 332, in _get_launcher
result = finder(distlib_package).find(name).bytes
File "C:\Program Files\Python36\lib\site-packages\pip_vendor\distlib\resources.py", line 324, in finder
raise DistlibException('Unable to locate finder for %r' % package)
pip._vendor.distlib.DistlibException: Unable to locate finder for 'pip._vendor.distlib'
You are using pip version 7.1.2, however version 9.0.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
So I try updating pip with py -m pip install --upgrade pip and it works most of the way until Rolling back uninstall of pip where it says:
Exception:
Traceback (most recent call last):
File "C:\Program Files\Python36\lib\site-packages\pip\basecommand.py", line 211, in main
status = self.run(options, args)
File "C:\Program Files\Python36\lib\site-packages\pip\commands\install.py", line 311, in run
root=options.root_path,
File "C:\Program Files\Python36\lib\site-packages\pip\req\req_set.py", line 646, in install
**kwargs
File "C:\Program Files\Python36\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\Python36\lib\site-packages\pip\req\req_install.py", line 998, in move_wheel_files
isolated=self.isolated,
File "C:\Program Files\Python36\lib\site-packages\pip\wheel.py", line 449, in move_wheel_files
generated.extend(maker.make(spec))
File "C:\Program Files\Python36\lib\site-packages\pip_vendor\distlib\scripts.py", line 353, in make
self._make_script(entry, filenames, options=options)
File "C:\Program Files\Python36\lib\site-packages\pip_vendor\distlib\scripts.py", line 257, in _make_script
self._write_script(scriptnames, shebang, script, filenames, ext)
File "C:\Program Files\Python36\lib\site-packages\pip_vendor\distlib\scripts.py", line 193, in _write_script
launcher = self._get_launcher('t')
File "C:\Program Files\Python36\lib\site-packages\pip_vendor\distlib\scripts.py", line 332, in _get_launcher
result = finder(distlib_package).find(name).bytes
File "C:\Program Files\Python36\lib\site-packages\pip_vendor\distlib\resources.py", line 324, in finder
raise DistlibException('Unable to locate finder for %r' % package)
pip._vendor.distlib.DistlibException: Unable to locate finder for 'pip._vendor.distlib'
You are using pip version 7.1.2, however version 9.0.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
Oddly enough, trying to just run pip in the command prompt it gives me 'pip' is not recognized as an internal or external command,
operable program or batch file.
I've tried uninstalling with py -m pip uninstall pip setuptools and reinstalling by running py get-pip.py on the python file, none of which seem to do anything.
So I have no way of uninstalling, reinstalling, or upgrading pip, and I can't use the current version of pip to install anything. I've searched for hours and tried changing my PATH variable and looking at file path limits, but I'm completly stuck and very new to this type of thing. I'm on Windows 10.
EDIT: "pip", "pip3", "python" and "python3" commands don't work. "py" command works.
EDIT: I seem to have gotten around using pip this time. I downloaded the discord package from github then followed instructions here which say to run py setup.py install --user. Still, I'd like to be able to use pip in the future.
There are couple solutions. You can reinstall python and during installation add it to environmental variable. Another way would be adding scripts and python to environmental path. http://www.correlatedsolutions.com/support/index.php?/Knowledgebase/Article/View/85/1/running-python-scripts-from-anywhere-under-windows.

Deploy Django on Python 3.6.2

I have downloaded Python 3.6.2 (64 bit) in Windows 10 (64 bit). Now I want to work on Django framework so I want to download Django using pip command but it shows Error.
C:\Windows\system32>pip install django
Collecting django
Using cached Django-1.11.4-py2.py3-none-any.whl
Collecting pytz (from django)
Using cached pytz-2017.2-py2.py3-none-any.whl
Installing collected packages: pytz, django
Exception:
Traceback (most recent call last):
File "c:\program files\python36\lib\site-packages\pip\basecommand.py", line 215, in main
status = self.run(options, args)
File "c:\program files\python36\lib\site-packages\pip\commands\install.py", line 342, in run
prefix=options.prefix_path,
File "c:\program files\python36\lib\site-packages\pip\req\req_set.py", line 784, in install
**kwargs
File "c:\program files\python36\lib\site-packages\pip\req\req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "c:\program files\python36\lib\site-packages\pip\req\req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "c:\program files\python36\lib\site-packages\pip\wheel.py", line 345, in move_wheel_files
clobber(source, lib_dir, True)
File "c:\program files\python36\lib\site-packages\pip\wheel.py", line 316, in clobber
ensure_dir(destdir)
File "c:\program files\python36\lib\site-packages\pip\utils\__init__.py", line 83, in ensure_dir
os.makedirs(path)
File "c:\program files\python36\lib\os.py", line 220, in makedirs
mkdir(name, mode)
PermissionError: [WinError 5] Access is denied: 'c:\\program files\\python36\\Lib\\site-packages\\pytz'
The problem has to do with the location you have chosen to install python, normally it's installed in C:\pythonXX but your installation is in C:\Program Files\pythonXX. That is always going to cause problems, you will need to always be running it as administrator. Quick and best solution, uninstall and accept to install python on the default location - C:\pythonXX
The best way to work with Django is within a virtual environment. Installing packages in your system's Python 3.6 will affect all programs you have running on Python 3.6; if you have multiple Django apps, your requirements could get all mixed up.
Django works really nicely with virtual environments: there's a good tutorial here. Essentially, you want to set up a virtual environment for each project, and then install Django (and its dependencies) cleanly within that environment. This should avoid any "Access denied" or other errors that you're experiencing.
Just as an example of how virtual environments help: if you need to use different versions of Django for different apps, they should be limited only to apps within that same virtual environment. Then, you can install the package differently in a different environment for another app. That way, when you "import django" from one of your apps, you know you're getting the version you need.

Error when installing XLRD using pip for python (3.6)

I am using windows 10 64-bit and i installed pip as well as python using the python installer. When i type the command pip install xlrd the following error appears :
C:\Users\Tanmay>pip install xlrd
Collecting xlrd
Downloading xlrd-1.0.0-py3-none-any.whl (143kB)
100% |████████████████████████████████| 153kB 317kB/s
Installing collected packages: xlrd
Exception:
Traceback (most recent call last):
File "c:\program files (x86)\python36-32\lib\site-packages\pip\basecommand.py", line 215, in main
status = self.run(options, args)
File "c:\program files (x86)\python36-32\lib\site-packages\pip\commands\install.py", line 342, in run
prefix=options.prefix_path,
File "c:\program files (x86)\python36-32\lib\site-packages\pip\req\req_set.py", line 784, in install
**kwargs
File "c:\program files (x86)\python36-32\lib\site-packages\pip\req\req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "c:\program files (x86)\python36-32\lib\site-packages\pip\req\req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "c:\program files (x86)\python36-32\lib\site-packages\pip\wheel.py", line 345, in move_wheel_files
clobber(source, lib_dir, True)
File "c:\program files (x86)\python36-32\lib\site-packages\pip\wheel.py", line 316, in clobber
ensure_dir(destdir)
File "c:\program files (x86)\python36-32\lib\site-packages\pip\utils\__init__.py", line 83, in ensure_dir
os.makedirs(path)
File "c:\program files (x86)\python36-32\lib\os.py", line 220, in makedirs
mkdir(name, mode)
PermissionError: [WinError 5] Access is denied: 'c:\\program files (x86)\\python36-32\\Lib\\site-packages\\xlrd'
it gives you Permission Error try to install it
as super user sudo pip install xlrd
in case of windows, in cmd try to run pip install using python executable
e.g.
`python -m pip install xlrd`
The problem got fixed simply by running the command prompt as an administrator.

Python Pip Install "Egg" Error (Pandas and other modules)

Having issues installing some python modules (for example pandas) and also had some issues installing ipython notebook.
This error seems to have come up before for other folks (Python pip install fails: invalid command egg_info), but they were using Python 2.7, whereas I'm using 2.6 (default with my Mac OS 10.6). Also I tried easy_install -U setuptools and pip install --upgrade setuptools but neither worked.
This is the error I get for installing pandas:
Command python setup.py egg_info failed with error code 1 in /private/var/folders/Wm/WmmbYincEnuCrAMtGBudAk+++TM/-Tmp-/pip_build_AWal/pandas
Storing debug log for failure in /Users/AWal/Library/Logs/pip.log
For installing iPython, this is the error that I get:
Exception:
Traceback (most recent call last):
File "/Library/Python/2.6/site-packages/pip-1.5.4-py2.6.egg/pip/basecommand.py", line 122, in main
status = self.run(options, args)
File "/Library/Python/2.6/site-packages/pip-1.5.4-py2.6.egg/pip/commands/install.py", line 283, in run
requirement_set.install(install_options, global_options, root=options.root_path)
File "/Library/Python/2.6/site-packages/pip-1.5.4-py2.6.egg/pip/req.py", line 1435, in install
requirement.install(install_options, global_options, *args, **kwargs)
File "/Library/Python/2.6/site-packages/pip-1.5.4-py2.6.egg/pip/req.py", line 671, in install
self.move_wheel_files(self.source_dir, root=root)
File "/Library/Python/2.6/site-packages/pip-1.5.4-py2.6.egg/pip/req.py", line 901, in move_wheel_files
pycompile=self.pycompile,
File "/Library/Python/2.6/site-packages/pip-1.5.4-py2.6.egg/pip/wheel.py", line 341, in move_wheel_files
generated.extend(maker.make_multiple(['%s = %s' % kv for kv in console.items()]))
File "/Library/Python/2.6/site-packages/pip-1.5.4-py2.6.egg/pip/_vendor/distlib/scripts.py", line 316, in make_multiple
filenames.extend(self.make(specification, options))
File "/Library/Python/2.6/site-packages/pip-1.5.4-py2.6.egg/pip/_vendor/distlib/scripts.py", line 305, in make
self._make_script(entry, filenames, options=options)
File "/Library/Python/2.6/site-packages/pip-1.5.4-py2.6.egg/pip/_vendor/distlib/scripts.py", line 209, in _make_script
self._write_script(scriptnames, shebang, script, filenames, ext)
File "/Library/Python/2.6/site-packages/pip-1.5.4-py2.6.egg/pip/_vendor/distlib/scripts.py", line 189, in _write_script
self._fileop.write_binary_file(outname, script_bytes)
File "/Library/Python/2.6/site-packages/pip-1.5.4-py2.6.egg/pip/_vendor/distlib/util.py", line 384, in write_binary_file
with open(path, 'wb') as f:
IOError: [Errno 13] Permission denied: '/usr/local/bin/sphinx-apidoc'
Storing debug log for failure in /Users/AWal/Library/Logs/pip.log
Any thoughts on what to do?
UPDATE:
When I do sudo pip install pandas (another module that I can't install), I get a long long traceback with the end error message:
RuntimeError: Broken toolchain: cannot link a simple C program
And traceback (a sample of it of the 100 or so lines) looks like this:
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/private/tmp/pip_build_root/pandas/setup.py", line 619, in <module>
**setuptools_kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/core.py", line 113, in setup
File "build/bdist.macosx-10.6-universal/egg/setuptools/dist.py", line 266, in __init__
File "build/bdist.macosx-10.6-universal/egg/setuptools/dist.py", line 312, in fetch_build_eggs
File "build/bdist.macosx-10.6-universal/egg/pkg_resources/__init__.py", line 753, in resolve
File "build/bdist.macosx-10.6-universal/egg/pkg_resources/__init__.py", line 1005, in best_match
File "build/bdist.macosx-10.6-universal/egg/pkg_resources/__init__.py", line 1017, in obtain
File "build/bdist.macosx-10.6-universal/egg/setuptools/dist.py", line 379, in fetch_build_egg
File "build/bdist.macosx-10.6-universal/egg/setuptools/command/easy_install.py", line 619, in easy_install
A permission Denied message would suggest you to run your command as root as suggested by Hackaholic.
try sudo pip install YOUR_PACKAGE
You might also want to have a look at virtualenv to use a more isolated environment.
Under debian based distributions, you might install python-virtualenv package with apt-get install python-virtualenv.
Then create a virtual environment names whatever by typing virtualenv whatever (this will create a folder whatever inside your current folder.
Then cd to it and type bin/activate to enter this virtual environment.
From there try again your pip install command.
Might help
UPDATE :
You might try to use the suggested solutions available here
To sumup, try to add export ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future inside ~/.bash_profile
This question comes first in Google, but the second one actually worked:
pip install -U setuptools
pip install ez_setup

Categories