pip: Missing distribution spec. How to fix this? - python

I am getting following error while running this command on my virtual machine:
$ sudo pip install -U -v --no-deps -b /tmp/piyush/ /tmp/piyush/common_bundle
File "/usr/local/lib/python2.7/dist-packages/pip-6.0.6-py2.7.egg/pip/_vendor/pkg_resources/__init__.py", line 2807, in parse_requirements
raise ValueError("Missing distribution spec", line)
ValueError: ('Missing distribution spec', '/tmp/piyush/common_bundle')
My input file is an archive.
$ file common_bundle
common_bundle: Zip archive data, at least v2.0 to extract
The version of pip is:
$ pip -V
pip 6.0.6 from /usr/local/lib/python2.7/dist-packages/pip-6.0.6-py2.7.egg (python 2.7)
Here is the pip manifest present in the common_bundle:
# This is a pip bundle file, that contains many source packages
# that can be installed as a group. You can install this like:
# pip this_file.zip
# The rest of the file contains a list of all the packages included:
PyYAML==3.10
boto==2.6.0
msgpack-python==0.2.2
tornado==2.1.1
ujson==1.22
virtualenv==1.8.2
bottle==0.10.7
raven==2.0.3
protobuf==2.4.1
# These packages were installed to satisfy the above requirements:
simplejson==2.4.0
distribute==0.6.32
Does anything look fishy?
Thanks.

When pip installing from an archive, the file must either have the proper extension or you need to explicitly use the file:// protocol. Rename your file to /tmp/piyush/common_bundle.zip or use file:///tmp/piyush/common_bundle.
The error you're seeing has nothing to do with the contents of the archive, pip hasn't even unpacked it yet.

Check to see if there are any spaces in your path. This was my problem. Also try keeping the path to the file as short as possible.

Related

How to pip install *.whl on Windows (using a wildcard)

For some reason, I cannot pip install %CD%\*.whl as I will then get:
Requirement 'C:\\Users\fredrik\\Downloads\\*.whl' looks like a filename, but the file does not exist
`*.whl is not a valid wheel filename.
On macOS (and I believe on Linux), I can do this without issues:
pip install *.whl
Processing ./certifi-2017.11.5-py2.py3-none-any.whl
Processing ./chardet-3.0.4-py2.py3-none-any.whl
Processing ./idna-2.6-py2.py3-none-any.whl
Processing ./requests-2.18.4-py2.py3-none-any.whl
Processing ./urllib3-1.22-py2.py3-none-any.whl
...
Why is there a difference in this behavior between the platforms?
Is there a preferred way to make this (pip install *.whl) work on Windows?
If you know the package name e.g. foo
You can use this:
python -m pip install --find-links=C:\Users\fredrik\Downloads foo
this will find any foo package e.g. foo-X.Y.Z-cp37-cp37m-win_amd64.whl etc...
If you don't know the package name then you can try:
FOR %%i in (C:\Users\fredrik\Downloads\*.whl) DO python -m pip install %i

pip install subdirectory for zip file

When using VCS, pip supports specifying a subdirectory:
https://pip.pypa.io/en/latest/reference/pip_install.html#examples.
Is it possible to specify the subdirectory when installing from a zip file?
Not sure if that's official, but actually works: pip install file:FULL_PATH.zip#subdirectory=SUB_PATH - without file the whole string is assumed to be a part of file name, including #subdirectory=.

How to change default install location for pip

I'm trying to install Pandas using pip, but I'm having a bit of trouble. I just ran sudo pip install pandas which successfully downloaded pandas. However, it did not get downloaded to the location that I wanted. Here's what I see when I use pip show pandas:
---
Name: pandas
Version: 0.14.0
Location: /Library/Python/2.7/site-packages/pandas-0.14.0-py2.7-macosx-10.9-intel.egg
Requires: python-dateutil, pytz, numpy
So it is installed. But I was confused when I created a new Python Project and searched under System Libs/lib/python for pandas, because it didn't show up. Some of the other packages that I've downloaded in the past did show up, however, so I tried to take a look at where those were. Running pip show numpy (which I can import with no problem) yielded:
---
Name: numpy
Version: 1.6.2
Location: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
Requires:
Which is in a completely different directory. For the sake of confirming my error, I ran pip install pyquery to see where it would be downloaded to, and got:
Name: pyquery
Version: 1.2.8
Location: /Library/Python/2.7/site-packages
Requires: lxml, cssselect
So the same place as pandas...
How do I change the default download location for pip so that these packages are downloaded to the same location that numpy is in?
Note: There were a few similar questions that I saw when searching for a solution, but I didn't see anything that mentioned permanently changing the default location.
According to pip documentation at
http://pip.readthedocs.org/en/stable/user_guide/#configuration
You will need to specify the default install location within a pip.ini file, which, also according to the website above is usually located as follows
On Unix and Mac OS X the configuration file is: $HOME/.pip/pip.conf
On Windows, the configuration file is: %HOME%\pip\pip.ini
The %HOME% is located in C:\Users\Bob on windows assuming your name is Bob
On linux the $HOME directory can be located by using cd ~
You may have to create the pip.ini file when you find your pip directory. Within your pip.ini or pip.config you will then need to put (assuming your on windows) something like
[global]
target=C:\Users\Bob\Desktop
Except that you would replace C:\Users\Bob\Desktop with whatever path you desire. If you are on Linux you would replace it with something like /usr/local/your/path
After saving the command would then be
pip install pandas
However, the program you install might assume it will be installed in a certain directory and might not work as a result of being installed elsewhere.
You can set the following environment variable:
PIP_TARGET=/path/to/pip/dir
https://pip.pypa.io/en/stable/user_guide/#environment-variables
Open Terminal and type:
pip config set global.target /Users/Bob/Library/Python/3.8/lib/python/site-packages
except instead of
/Users/Bob/Library/Python/3.8/lib/python/site-packages
you would use whatever directory you want.
Follow these steps
pip config set global.target D:\site-packages to change install path
or py -m pip config --user --editor notepad edit
[global]
target = D:\site-packages
set environment variable to use download import xxx
PIP_TARGET=site-packages
PYTHONPATH=site-packages
3.pip config unset global.target, to upgrade pip py -m pip install --upgrade pip
#Austin's answer is outdated, here for more up-to-date solution:
According to pip documentation at
https://pip.pypa.io/en/stable/topics/configuration/
You will need to specify the default install location within a configuration file, which, also according to the website above is usually located as follows
Mac OS
$HOME/Library/Application Support/pip/pip.conf if directory $HOME/Library/Application Support/pip exists else $HOME/.config/pip/pip.conf.
The legacy “per-user” configuration file is also loaded, if it exists: $HOME/.pip/pip.conf.
The $HOME folder can be located by navigating to ~/ (cmd+shift+G in Finder; cmd+shift+. to show hidden files).
Windows
%APPDATA%\pip\pip.ini
The legacy “per-user” configuration file is also loaded, if it exists: %HOME%\pip\pip.ini
The %HOME% is located in C:\Users\Bob on windows assuming your username is Bob
Unix
$HOME/.config/pip/pip.conf, which respects the XDG_CONFIG_HOME environment variable.
The legacy “per-user” configuration file is also loaded, if it exists: $HOME/.pip/pip.conf.
On linux the $HOME directory can be located by using cd ~
You may have to create the configuration file when you find your pip directory. Put something like
[global]
target = /Library/Frameworks/Python.framework/Versions/Current/lib/python3.10/site-packages/
if you are on a Mac. Except that you would replace /Library/Frameworks/Python.framework/Versions/Current/lib/python3.10/site-packages/ with whatever path you desire. If you are on Linux you would replace it with something like /usr/local/your/path
After saving the command would then be
pip install pandas
However, the program you install might assume it will be installed in a certain directory and might not work as a result of being installed elsewhere.
Please note that
pip3 install pandas
might be the solution if your packages gets installed in the Python2 folder vs Python3.

Installing a pip package from a local SVN checkout

I have a clone of another python project (that has a setup.py etc.) in my svn repository. I want to install tell pip to install from this directory. However it's an internal svn repo and is accessible via the svn:// scheme, not http://.
I can checkout the directory fine like so svn co svn://172.31.1.3/Development/Common/ThirdParty/Python/package/our-version ./foobar, then install it with pip: pip install foobar/, however I can't make it do it all in one go.
Here is what I've tried and the output:
pip install svn://172.31.1.3/Development/Common/ThirdParty/Python/package/our-version
...
File ".../virtualenv/lib/python2.5/site-packages/pip-0.7.2-py2.5.egg/pip/vcs/__init__.py", line 110, in get_url_rev
url = self.url.split('+', 1)[1]
IndexError: list index out of range
and
pip install svn+svn://172.31.1.3/Development/Common/ThirdParty/Python/package/our-version
...
File "...virtualenv/lib/python2.5/site-packages/distribute-0.6.10-py2.5.egg/pkg_resources.py", line 2424, in scan_list
raise ValueError("Expected "+item_name+" in",line,"at",line[p:])
ValueError: ('Expected version spec in', 'svn+svn://172.31.1.3/Development/Common/ThirdParty/Python/package/our-version', 'at', '+svn://172.31.1.3/Development/Common/ThirdParty/Python/package/our-version')
Both of these problems happen with or without #egg=packagename at the end of the URL (with the same error message).
and as an editable URL:
pip install -e svn://172.31.1.3/Development/Common/ThirdParty/Python/package/our-version#egg=package
Obtaining package from svn+svn://172.31.1.3/Development/Common/ThirdParty/Python/package/our-version#egg=package
Checking out svn://172.31.1.3/Development/Common/ThirdParty/Python/package/our-version#egg=package to ../virtualenv/src/package
svn: URL 'svn://172.31.1.3/Development/Common/ThirdParty/Python/package/our-version#egg=package' is not properly URI-encoded
So SVN complains if there's a #egg=package at the end of the url, and if i leave it out, I get this error:
pip install -e svn://172.31.1.3/Development/Common/ThirdParty/Python/package/our-version
--editable=svn://172.31.1.3/Development/Common/ThirdParty/Python/package/our-version is not the right format; it must have #egg=Package
How do I install a package from an SVN link with pip?
It is an open bug right now. Paul Nasrat is taking a look at it and opened and issue.
Follow the https://github.com/pypa/pip/issues/252

How to install python-dateutil on Windows?

I'm trying to convert some date/times to UTC, which I thought would be dead simple in Python - batteries included, right? Well, it would be simple except that Python (2.6) doesn't include any tzinfo classes. No problem, a quick search turns up python-dateutil which should do exactly what I need.
The problem is that I need to install it on Windows. I was able to upack the .tar.gz2 distribution using 7-zip, but now I'm left with a collection of files and no guidance on how to proceed. When I try to run setup.py I get the error "No module named setuptools".
If dateutil is missing install it via:
pip install python-dateutil
Or on Ubuntu:
sudo apt-get install python-dateutil
Why didn't someone tell me I was being a total noob? All I had to do was copy the dateutil directory to someplace in my Python path, and it was good to go.
Looks like the setup.py uses easy_install (i.e. setuptools). Just install the setuptools package and you will be all set.
To install setuptools in Python 2.6, see the answer to this question.
Install from the "Unofficial Windows Binaries for Python Extension Packages"
http://www.lfd.uci.edu/~gohlke/pythonlibs/#python-dateutil
Pretty much has every package you would need.
It is a little tricky for people who is not used to command prompt. All you have
to do is open the directory where python is installed (C:\Python27 by default) and open the command prompt there (shift + right click and select open command window here) and then type :
python -m pip install python-dateutil
Hope that helps.
Using setup from distutils.core instead of setuptools in setup.py worked for me, too:
#from setuptools import setup
from distutils.core import setup
If you are offline and have untared the package, you can use command prompt.
Navigate to the untared folder and run:
python setup.py install
Just run command prompt as administrator and type this in.
easy_install python-dateutil
You could also change your PYTHONPATH:
$ python -c 'import dateutil'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named dateutil
$
$ PYTHONPATH="/usr/lib/python2.6/site-packages/python_dateutil-1.5-py2.6.egg":"${PYTHONPATH}"
$ export PYTHONPATH
$ python -c 'import dateutil'
$
Where /usr/lib/python2.6/site-packages/python_dateutil-1.5-py2.6.egg is the place dateutil was installed in my box (centos using sudo yum install python-dateutil15)
First confirm that you have in C:/python##/Lib/Site-packages/ a folder dateutil, perhaps you download it, you should already have pip,matplotlib, six##,,confirm you have installed dateutil by--- go to the cmd, cd /python, you should have a folder /Scripts. cd to Scripts, then type --pip install python-dateutil --
----This applies to windows 7 Ultimate 32bit, Python 3.4------
I followed several suggestions in this list without success. Finally got it installed on Windows using this method: I extracted the zip file and placed the folders under my python27 folder. In a DOS window, I navigated to the installed root folder from extracting the zip file (python-dateutil-2.6.0), then issued this command:
.\python setup.py install
Whammo-bammo it all worked.

Categories