I have python2.6 as my default python and I've been using distribute easy_install to install packages in ~/.local. easy_install has many issues and I'd like to switch to pip, while at the same time upgrading to python2.7 from python2.6. My existing pip version is tied to python2.6 and always looks in ~/.local/lib/python2.6 for packages. This means I have to install pip again with Python2.7 but it seems like this cannot be done with the existing python2.6 pip, right?
Therefore I tried to download pip and install it like this:
python2.7 setup.py install --prefix=~/.local
Note that I do not have root, so I have to install pip locally. When I try this I get:
Traceback (most recent call last):
File "setup.py", line 5, in <module>
from setuptools import setup
ImportError: No module named setuptools
How can I fix this situation? I obviously cannot install setuptools with pip, because I can't install pip... all I want to do is link up pip with python2.7, upgrade pip and then install everything with pip and forget about easy_install and the old python2.6 and its packages.
When I try the answer below, I get:
The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/home/user/.local/lib/python2.7/site-packages
This directory does not currently exist. Please create it and try again, or
choose a different installation directory (using the -d or --install-dir
option).
I had to manually create (with mkdir) the directory:
~/.local/lib/python2.7/site-packages
This seems broken... it worked once I did it, but why does it require manual creation of a directory?
thanks.
You need to install setuptools first; it has it's own installation script (it's part of the egg file):
wget "http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg"
sh setuptools-0.6c11-py2.7.egg --prefix=~/.local
Note that it, too, supports a --prefix= option. It'll find your python2.7 binary (and not the 2.6 version) because you downloaded the 2.7 egg version.
Related
I downloaded the newest Cython release from https://pypi.python.org/pypi/Cython/#downloads. I'm working in Python 3.5.1 on a Mac so I downloaded
Cython-0.26.1-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
I unzipped it and entered the /Cython directory, but there is no setup.py in the directory. When I try to run python3 setup.py install anyway I get the following error:
/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/Resources/Python.app/Contents/MacOS/Python: can't open file 'setup.py': [Errno 2] No such file or directory
It doesn't seem to be looking in the /Cython directory I am in, but there is also no setup.py in that directory.
Not sure what's going on, I can't seem to find anyone else having this issue.
I've install python3 using homebrew.
The file you downloaded is a wheel file that should be installed using pip. The wheel file does not include the setup.py script which is required to build the package but is not used when installing wheels. First check you are using correct pip command (you need one for python 3.5), this is usually pip3.5 or pip3 command:
$ pip3 -V
pip 9.0.1 from /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages (python 3.5)
To install cython from the downloaded wheel, issue
$ pip3 install path/to/downloaded.whl
Or simply issue
$ pip3 install cython
as pip will download the latest package wheel for you. Since you installed python 3.5 via Homebrew, you probably have to switch to the user you use to install packages with Homebrew or the installation with pip will fail.
Note that, although suggested in the comments, it is not advised to install cython package via brew install:
$ brew info cython
...
==> Caveats
This formula is keg-only, which means it was not symlinked into
/usr/local,
because this formula is mainly used internally by other formulae.
Users are advised to use `pip` to install cython.
I'm using Mac OS X 10.10. I want to use pip to install packages for my homebrew installed version of python (located in /usr/local/bin/python, which is an alias that points to /usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/bin). It appears that site-packages for this version are here: /usr/local/lib/python2.7/site-packages/.
which python returns /usr/local/bin/python
which pip returns /usr/local/bin/pip
These seem correct to me.
Trying something like pip install pylzma returns:
Collecting pylzma
Installing collected packages: pylzma
Successfully installed pylzma
You are using pip version 8.0.2, however version 8.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
But then pip list does not show pylzma to be installed. It looks like pip installs the packages to /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (the python that ships with Mac OS X).
How can I get pip to install to my homebrewed python?
I've tried a number of suggestions from similar questions:
I've tried export PATH=/usr/local/bin/python:${PATH}.
I've tried pip install --install-option="--prefix=/usr/local/lib/python2.7" pylzma.
I've tried changing the first line of the pip executable script to #!/usr/local/bin/python
I've tried /usr/local/bin/python -m pip install pylzma.
But none of these work. I also tried upgrading pip to 8.1.1, but that made pip break entirely. People recommend using virtualenv, but as far as I know, I can't install that without pip.
When I type python -m pip, it says:
Usage:
/usr/local/opt/python/bin/python2.7 -m pip <command> [options]
Could that be a problem?
My issue was that my /Users/<username>/.pydistutils.cfg contained the following:
[easy_install]
# set the default location to install packages
install_dir = /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
[install]
install_lib = /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
install_scripts = ~/bin
I changed this to:
[easy_install]
# set the default location to install packages
install_dir = /usr/local/lib/python2.7/site-packages
[install]
install_lib = /usr/local/lib/python2.7/site-packages
install_scripts = ~/bin
That seemed to have worked. pip install now installs packages to the desired location /usr/local/lib/python2.7/site-packages.
However, I am have ongoing path issues.
import pylzma still gives me ImportError: No module named pylzma.
and running jupyter notebook in terminal gives -bash: jupyter: command not found. /Users/<username>/bin/jupyter notebook does execute, but I get ImportError: No module named markupsafe despite the fact that /usr/local/lib/python2.7/site-packages/MarkupSafe-0.23.dist-info exists.
EDIT: I got jupyter notebook working eventually. I had to install several packages from the source tarballs directly, including MarkupSafe, functools32, and jsonschema. Maybe Python is not looking in the correct folder or something.
I think that somehow the path /lib is stored in my python dist where it should not be.
It started when I was having troubles installing python modules using pip. Pip seemed to install everything into /lib/python2.7/site-packages where python could not find it.
Sidenote: pip uninstall could not find the package in /lib either, but it is where pip install would install it.
I tried:
which pip
$/usr/bin/pip
$which python
/usr/bin/python
I decided to uninstall pip, but then
$ easy_install uninstall pip
error: can't create or remove files in install directory
The following error occurred while trying to add or remove files in the
installation directory:
[Errno 13] Permission denied: '/lib'
The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/lib/python2.7/site-packages/
It seemed that even in my easy-install, the '/lib' location was used. I googled a bit, and decided to reinstall easy-install. I removed it:
$sudo rm /usr/local/bin/easy_install
And tried to install it again:
$ sudo curl https://bootstrap.pypa.io/ez_setup.py -o - | python
Checking .pth file support in /lib/python2.7/site-packages/
error: can't create or remove files in install directory
So my problem is basically that I want to get my python installation as clean as possible, and that this /lib location is stored somewhere.
Some side information
I am getting more familiar with the file structure of python now but I used to know little about it. I also had many problems installing python packages so I used many different python versions trough tutorials. (Via brew, canopy, anaconda, ipython). I uninstall most of them because I just want a clean installation as possible. (I once had tried to uninstall a site-package and I discovered that it was stored in 4 different locations simultaniously!)
$ which python
/usr/bin/python
Most of my site-packages right now are installed in:
/usr/local/lib/python2.7/site-packages
/Users/myusersname/Library/Python/2.7/lib/python/site-packages
Empty:
$ echo $PYTHONPATH
OS-X 10.9.5
I hope you guys can help me!
easy install pip
I want to get everything as clean as possible so I uninstalled my homebrew version of python.
EDIT:
Python from homebrew
So I uninstalled all python versions except the system one (/usr/bin/python). Now I tried to install python via homebrew (/usr/local/bin/python does link to cellar).
When I try to run pip:
$which pip
/usr/local/pip
$pip
Traceback (most recent call last):
File "/usr/local/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2603, in <module>
working_set.require(__requires__)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 666, in require
needed = self.resolve(parse_requirements(requirements))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 565, in resolve
raise DistributionNotFound(req) # XXX put more info here
pkg_resources.DistributionNotFound: pip==1.5.6
When I try to
sudo easy_install -U pip
TEST FAILED: /lib/python2.7/site-packages/ does NOT support .pth files
error: bad install directory or PYTHONPATH
Python from python.org
I uninstalled homebrew python and installed python using the GUI installer from the website. I checked that /usr/local/bin/python does link to this python.
This python does not come with pip or easy install. So I run setuptools:
$ sudo python ez_setup.py
Extracting in /tmp/tmpR80Ydp
Now working in /tmp/tmpR80Ydp/setuptools-7.0
Installing Setuptools
running install
Checking .pth file support in /lib/python2.7/site-packages/
/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -E -c pass
TEST FAILED: /lib/python2.7/site-packages/ does NOT support .pth files
error: bad install directory or PYTHONPATH
You are attempting to install a package to a directory that is not
on PYTHONPATH and which Python does not read ".pth" files from. The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/lib/python2.7/site-packages/
This is the error I am allways getting. It is very persistent and I hope you guys can help me with it. I allready tried some of the solutions here:
Python pip broken after OS X 10.8 upgrade
pip install on Mac OS X - PYTHONPATH
but nothing helps.
Setting the PYTHONPATH or running with or witouth sudo doesn't help eigther.
export PYTHONPATH='/Library/Python/2.7/site-packages'
If you want to get your python installation as clean as possible you should consider using a virtual environment.
$ sudo pip install virtualenv
$ pyvenv env # create a virtual environment
$ source env/bin/activate # activate the virtual environment
(env) $ curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python # install pip in the virtualenv
This code works for python 3.4 but it should be something similar for python 2.7. Then you can install packages as you would normally do:
(env) $ pip install [package name]
All the packages you install this way will be saved in the "env" directory. If you want to run a program inside the virtual environment you have to activate it first. When you are done, you can simply deactivate it.
(env) $ deactivate
I first downloaded Python 3.3 with the purpose of then adding xlrd and xlwt to use with excel. I have been unable to install easy_install, distribute, or either of the above.
This is an error message I get after downloading distribute, extracting it and running distribute_setup.py from IDLE:
Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.49.tar.gz
Extracting in c:\users\t\appdata\local\temp\tmpecnfj9
Now working in c:\users\t\appdata\local\temp\tmpecnfj9\distribute-0.6.49
Installing Distribute
Something went wrong during the installation.
See the error message above.
Traceback (most recent call last):
File "C:\Python33\Lib\site-packages\distribute-0.6.49\distribute_setup.py", line 556, in <module>
sys.exit(main())
SystemExit: 2
Overall, I am unable to install and use any modules. I assume I am missing a very basic step.
In Python 3.3, setuptools replaces distribute. Download and install setuptools and you should be good to go. You might also want to consider installing pip after installing setuptools. Follow the directions for setuptools and pip in pypi.
Install Python in a drive where you have downloaded the Python Source which is in .msi format or you can change the drive of that source file and then try to install it. Just a simple installation process, nothing typical.
No worries. Make sure you have done the following
Ensure that you have python and pip installed and accessible from the command line. Type both of these commands to ensure that you have python and pip3 installed:
a. pip3
b. python3
If you got any message telling you that you do not have them installed on your system
Use the pip3 install PACKAGE_NAME_HERE command in your terminal/cmd to install modules/packages
If you get the pip3 command not found error, then type the respective command
a)If you are on a mac device, install brew: brew install python3. Then install pip3: brew postinstall python3. Then call pip3 -V to see if it works.
b) If you are on a Linux device, use, sudo apt install python3-pip to install pip
I installed python26 using macports, so the correct python on my system is /opt/local/bin/python
However, when I do
sudo pip install <packagename>
It gives me
sudo pip install <somepackage>
Exception:
Traceback (most recent call last):
File "/Library/Python/2.6/site-packages/pip-1.0.1-py2.6.egg/pip/basecommand.py", line 126, in main
self.run(options, args)
File "/Library/Python/2.6/site-packages/pip-1.0.1-py2.6.egg/pip/commands/install.py", line 215, in run
import setuptools
ImportError: No module named setuptools
Storing complete log in /Users/navin/.pip/pip.log
And so, I suspect that it is using the system python. I've installed distribute (which contains setuptools) via their site instructions. I installed pip via an installer as well. I somehow managed to clobber the setuptools for the system python I think, so that's why I'm having this problem now :(
What do I do to get pip working again?
UPDATE: I strongly recommend installing CPython by building from source (example), and then creating virtual environments to work in.
Summarizing the above, installing pip using Macports:
sudo port install py39-pip
results in an installation of a MacPorts port named py39-pip.
However, no /opt/local/bin/pip is installed and port select pip or port select py27-pip both fail (in contrast to port select python). Changing things in the bin directory of another distribution is not recommended.
Note that Python files in:
/usr/bin are of the preinstalled Python of macOS
/usr/local/bin are installed by MacPython, available from python.org
/opt/local/bin are installed by MacPorts.
The actual executable files can be found by ls -ls applied to the various Python-related symbolic links found in each of the above bin directories).
To ensure that the Python installed by MacPorts is called first, place /opt/local/bin within the runtime environment's PATH earlier than /usr/bin and /usr/local/bin. This can be done in the file ~/.bash_profile or the file ~/.bashrc (which one depends on your system and configuration). For example, writing
export PATH=/opt/local/bin:$PATH
last in ~/.bashrc will have this effect (assuming that the intended shell will source the file ~/.bashrc).
After the paths have been appropriately defined, the system still fails to find a pip command in the Macports bin directory, because it is installed as /opt/local/bin/pip3.9. The file /opt/local/bin/pip is not automatically created.
As a result, the system continues searching the PATH, and if e.g. MacPython is added to the path some place later and has pip installed, then that pip will show up.
This can be avoided by the command proposed above:
sudo ln -s /opt/local/bin/pip3.9 /opt/local/bin/pip
Remove pip from /usr/local/bin with sudo rm /usr/local/bin/pip.
If you have installed pip with macports, which pip should then show /opt/local/bin/pip. If not, install pip again by following the instructions here. As long as which python shows the /opt/local installation, it should work. If it doesn't, you will need to edit your PATH env variable.
Here is my setup to get pip working with macports and set py26-pip as the default pip
sudo port install py26-pip && sudo port select --set pip py26-pip
after install finishes run to see the help information for pip
pip --help
after you may need to update your path to include the bin files installed by pip edit .bash_profile to include something like
export PATH=/opt/local/bin:/opt/local/sbin:/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin:$PATH
You should have the python and pip installed in /opt/local/bin/ prior to those installed in /usr/local/bin/.
Also, you should check to execute which python and whether the pip was installed in /opt/local/bin/pip.
I found I needed to ln -s /opt/local/bin/pip-2.7 /opt/local/bin/pip. For some reason macports didn't built that link, even when you try activating that version of python or pip.