# echo $PYTHONPATH
/usr/lib/python3.6/site-packages
# whoami
root
# easy_install --prefix=/usr/lib/python3.6/site-packages django==1.9
TEST FAILED: /usr/lib/python3.6/site-packages/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:
/usr/lib/python3.6/site-packages/lib/python2.7/site-packages
and your PYTHONPATH environment variable currently contains:
'/usr/lib/python3.6/site-packages'
Here are some of your options for correcting the problem:
* You can choose a different installation directory, i.e., one that is
on PYTHONPATH or supports .pth files
* You can add the installation directory to the PYTHONPATH environment
variable. (It must then also be on PYTHONPATH whenever you run
Python and want to use the package(s) you are installing.)
* You can set up the installation directory to support ".pth" files by
using one of the approaches described here:
https://pythonhosted.org/setuptools/easy_install.html#custom-installation-locations
Please make the appropriate changes for your system and try again.
# ls /usr/lib/python3.6/site-packages/lib/python2.7/site-packages
#
After reading answer, I couldn't find .pydistutils.cfg file in the file system
easy_install command tries to install in install path/usr/lib/python3.6/site-packages/lib/python2.7/site-packages which is invalid. This install path is getting created, amidst easy_install
Question:
How to resolve the install path using easy_install?
1.Are you using easy_install that works with Python2? Try to use easy_install that works with Python3.
Look at this.
2.--prefix set installation prefix.
When you use easy_install --prefix=/usr/lib/python3.6/site-packages,
the dir is :
'/usr/lib/python3.6/site-packages/' + 'lib/python2.7/site-packages'
Maybe you should use --install-dir
Related
I'm building a python package to use for 'global' functions (i.e. stuff that I will use in multiple other projects). I have built the package using py -m build and it then puts the MyPackage-0.1.0.tar.gz into the dist directory in my folder.
My goal is to be able to run pip install MyPackage from within any other projects, and it will install the latest build of my package. In other words, I do not want to use something like --find-links. This way, I could also include the package in a requirements.txt file.
I have tried putting the tarball in a directory which is on my system's PATH, and into a subfolder within there (e.g. PathDir/MyPackage/MyPackage-0.1.0.tar.gz), but I keep getting the same 'No matching distribution found' error.
The documentation for pip install says:
pip looks for packages in a number of places: on PyPI (if not disabled via --no-index), in the local filesystem, and in any additional repositories specified via --find-links or --index-url.
When it says 'in the local filesystem' where does it begin it's search? Is there a way to change this (e.g. set some environment variable)
When looking for files in the local filesystem, pip has no notion of search path. You must give a path accessible from the current working directory. It can be an absolute path:
pip install /path/to/MyPackage-0.1.0.tar.gz
a relative path:
cd /path
pip install to/MyPackage-0.1.0.tar.gz
or a simple name if the package file is inside the current working directory:
cd /path/to
pip install MyPackage-0.1.0.tar.gz
I found the answer after a lot of searching, and so here is the solution:
pip uses configuration files to define its internal settings. In these configuration files, you can specify default values for find-links. This means that python will look here for compatible packages, as well as online.
You can check what configurations have been set, and what files they will be searched in by running pip config list -v. You just need to edit/create one of the files listed and add your configuration as pip.ini with the following:
[install]
find-links=file://C:/Users/.../PathDir/MyPackage/
By creating this at the User/Global level (rather than the site level), this installation also works when inside a virtual environment.
Source: https://pip.pypa.io/en/stable/topics/configuration/
pip can install packages from the local file system. They do not need to be even package files, they can be just working directories or git checkouts.
Usually I use pip --editable:
pip --editable /path/to/my/python/package
With --editable changes in .py files in the folder are automatically reflected to your application.
You can use --editable in requirements.txt file as well.
I am using a Mac and I get an error message on my terminal when I try to install Beautiful Soup. I have Python 3 installed already.
This is what I did after unpacking the Beautiful Soup zip file
$ cd Users/thepredestrian/Desktop/beautifulsoup4-4.4.1
$ python setup.py install
This is the error message that appears:
Checking .pth file support in /Library/Python/2.7/site-packages/
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: '/Library/Python/2.7/site-packages/test-easy-install-966.pth'
The installation directory you specified (via --install-dir, --prefix,
or the distutils default setting) was:
/Library/Python/2.7/site-packages/
Perhaps your account does not have write access to this directory? If the
installation directory is a system-owned directory, you may need to sign in
as the administrator or "root" account. If you do not have administrative
access to this machine, you may wish to choose a different installation
directory, preferably one that is listed in your PYTHONPATH environment
variable.
For information on other options, you may wish to consult the
documentation at:
https://pythonhosted.org/setuptools/easy_install.html
Please make the appropriate changes for your system and try again
Any advice appreciated!
Try installing with sudo.
sudo python setup.py install
An alternate way is to use virtual environment. Inside a virtual environment, you can install dependencies locally rather than system wide, so you won't need access to a root account.
pip install virtualenv
virtualenv test
cd test
source bin/activate
The first line installs virtualenv. The second line creates a virtual environment. The third and fourth line activates (starts) the virtualenv. You will notice the change in prompt. Inside virtualenv, you can install dependencies (e.g BeautifulSoup), run python scripts and so on. Once you're done, you can deactivate the environment by simply typing deactivate in the shell.
I am trying to install pip on my OS X 10.9.4 machine. I've had problems with different versions of python in the past but I think I've fixed these issues by deleting the corresponding files.
This is what I get when I try sudo easy_install pip:
╭─ishaantaylor#Ishaans-MacBook-Pro.local ~
╰─➤ sudo easy_install pip 1 ↵
Password:
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/
and your PYTHONPATH environment variable currently contains:
''
Here are some of your options for correcting the problem:
* You can choose a different installation directory, i.e., one that is
on PYTHONPATH or supports .pth files
* You can add the installation directory to the PYTHONPATH environment
variable. (It must then also be on PYTHONPATH whenever you run
Python and want to use the package(s) you are installing.)
* You can set up the installation directory to support ".pth" files by
using one of the approaches described here:
http://peak.telecommunity.com/EasyInstall.html#custom-installation-locations
Please make the appropriate changes for your system and try again.
And then I added export PYTHONPATH="/lib/python2.7/site-packages/" to my ~/.zprofile (I'm using zsh).
I source ~/.zprofile and deleted the corrupted pip from my system and tried sudo easy_install pip again and I got the exact same error.
Could somebody please tell me what I am doing wrong, and what to do to fix it? Also could anybody recommend any resources that I could read to better understand the way these things work?
I want to install Sphinx 1.1.3 for python 2.6. However, I don't have sudo rights. So instead of installing it in the default place, I want to set a different location, using --prefix. Doing the following:
-bash-3.2$ easy_install Sphinx-1.1.3-py2.6.egg --prefix=/homes/ndeklein/python2.6/site-packages/
gives me:
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: '/usr/lib/python2.4/site-packages/test-easy-install-18534.write-test'
The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/usr/lib/python2.4/site-packages/
Am I typing something wrong with the prefix? Also, what I could use instead (which I've used with other packages):
python setup.py install --home=/homes/ndeklein/python2.6/site-packages/
but I can't find the setup.py script. I'm guessing that EGGs don't have a setup.py script, is that true?
You need to specify options before the package, so the command should be:
easy_install --prefix=/homes/ndeklein/python2.6/site-packages/ Sphinx-1.1.3-py2.6.egg
This website discusses non-root python installs. It might be useful to you...
http://www.astropython.org/tutorials/user-rootsudo-free-installation-of-python-modules7/
To quote a little bit of it:
A user configuration file, ~/.pydistutils.cfg, will override the internal system path for python package installations, redirecting the built libraries (lib), scripts (bin) and data (share) into user owned and specified directories. You must simply tell the python installer where theses directories are located.
The user file, ~/.pydistutils.cfg, has the following lines, using a pretty obvious syntax:
[install]
install_scripts = ~/usr/bin
install_data = ~/usr/share
install_lib = ~/usr/lib/python2.4/site-packages
Of course, whatever directories you specify there should probably exist and you should put them at the front of your PYTHONPATH:
export PYTHONPATH=~/usr/lib/python2.4/site-packages:${PYTHONPATH}
It also looks like more modern python installations (compared to the things in the link) should be able to use the ~/.local directory:
easy_install --prefix=~/.local ...
There is also:
easy_install --user ...
which will install to a user-specific site directory.
You could try using pip install of easy_install(pip is recommended over easy_install these days)
Then you can just use
pip install --user Sphinx
see http://www.pip-installer.org/en/latest/installing.html on how to install pip if needed
You may also want to pip install virtualenv and work inside virtualenv(where pip will install all packages in a local site packages folder). see http://pypi.python.org/pypi/virtualenv for more info.
I tried to install python below way. But this did not work.
This take "error: bad install directory or PYTHONPATH".
What's the proper way to install pip, virtualenv, and distribute for Python?
Make directory
$ mkdir -p ~/.python
Add .bashrc
#Use local python
export PATH=$HOME/.python/bin:$PATH
export PYTHONPATH=$HOME/.python
Create a file ~/.pydistutils.cfg
[install]
prefix=~/.python
Get install script
$ cd ~/src
$ curl -O http://python-distribute.org/distribute_setup.py
Execute and Error
$ python ./distribute_setup.py
Extracting in /tmp/tmpsT2kdA
Now working in /tmp/tmpsT2kdA/distribute-0.6.15
Installing Distribute
Before install bootstrap.
Scanning installed packages
No setuptools distribution foundrunning install
Checking .pth file support in /home/sane/.python/lib/python2.6/site-packages//usr/bin/python -E -c pass
TEST FAILED: /home/sane/.python/lib/python2.6/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:
/home/sane/.python/lib/python2.6/site-packages/
and your PYTHONPATH environment variable currently contains:
'/home/sane/.python'
Here are some of your options for correcting the problem:
* You can choose a different installation directory, i.e., one that is
on PYTHONPATH or supports .pth files
* You can add the installation directory to the PYTHONPATH environment
variable. (It must then also be on PYTHONPATH whenever you run
Python and want to use the package(s) you are installing.)
* You can set up the installation directory to support ".pth" files by
using one of the approaches described here:
http://packages.python.org/distribute/easy_install.html#custom-installation-locations
Please make the appropriate changes for your system and try again.
Something went wrong during the installation.
See the error message above.
My environment('sane' is my unix user name.)
$ python -V
Python 2.6.4
$ which python
/usr/bin/python
$ uname -a
Linux localhost.localdomain 2.6.34.8-68.fc13.x86_64 #1 SMP Thu Feb 17 15:03:58 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
Usually I installed distributed/easy_install aka setuptools in my global Python installation together with virtualenv. From this point on I can created dedicated virtualalized environments using
virtualenv --no-site-packages name-of-environment
Really no idea why to fiddle around with PYTHONPATH here.
Adding /path/to/name-of-environment/bin to $PATH is good enough for adding the virtualized
Python to your $PATH. You don't need any else.
I choice pythonbrew.
I can use multiple Pythons in my home directory by this.
It's a great job.
utahta/pythonbrew - GitHub https://github.com/utahta/pythonbrew