Confusing Python install in user local (virtualenv, pip, distribute) - python

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

Related

Can't find jedi-language-server in command line in mac but can in Linux

Questions
I install jedi-language-server as the README.md. but I can't find jedi-language-server --help in My Mac(13 Ventura) system. But I can find this package in the pip list.
➜ ~ pip3 list | grep jedi
jedi 0.18.2
jedi-language-server 0.40.0
PATH and others
This is my new machine, not use conda or other venv moudle.
➜ ~ echo $PATH
/Users/vzgoll/bin:/usr/local/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin
➜ ~ which jedi-language-server
jedi-language-server not found
➜ ~ python3 -m site
sys.path = [
'/Users/vzgoll',
'/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python39.zip',
'/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9',
'/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/lib-dynload',
'/Users/vzgoll/Library/Python/3.9/lib/python/site-packages',
'/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/site-packages',
]
USER_BASE: '/Users/vzgoll/Library/Python/3.9' (exists)
USER_SITE: '/Users/vzgoll/Library/Python/3.9/lib/python/site-packages' (exists)
ENABLE_USER_SITE: True
In order to verify, I install jedi-language-server in my Arch Linux, It can use command jedi-language-server --help
So I want to ask why this happened.
Solution
Add following code in my ~/.zshrc.
pythonUserBaseDir=$(python3 -m site --user-base);
pythonUserBaseBinDir="$pythonUserBaseDir/bin"
export PATH="$pythonUserBaseBinDir:$PATH"
unset pythonUserBaseDir;
unset pythonUserBaseBinDir;
It's a $PATH problem.
You didn't reveal anything about your conda or venv
config, and you didn't show us what $ echo $PATH says.
You should have a python project environment for
installing jedi and dependencies.
When you activate the environment, the relevant /bin
directory should be added to your $PATH.
Apparently that only happened properly on your Linux install.
Use $ which jedi-language-server and $ ls -l to
debug the details, so your Mac config resembles
the (working) Linux config.
Use $ python -m site to examine the
python library install directories.
Notice how its output changes when you
activate or deactivate the project environment.
EDIT
You're not using a project environment
for python library installs?
I don't recommend that.
There are very good reasons for using such
an environment, which the current question is highlighting.
Perhaps you used sudo when you pip installed it?
Where did the install go?
Use ls -l or find to locate it.
Verify that you have permission to read the
root-owned file.
Verify that you have added its directory
to your $PATH environment variable.
You have two OS environments, one of them working.
Use the tools mentioned above to find how
they differ, and to repair the faulty install.
Focus on that
/Users/vzgoll/Library/Python/3.9/lib/python/site-packages
directory.
You should see several recently installed libraries
in there, perhaps including jedi.
Sometimes a library will include a bin directory
under site-packages.
You should be able to run binaries by giving
the full path, or more conveniently by appending the bin directory
to your $PATH env var.

Make Python 3.6.6 run with python3 and not python

I just installed python 3.6.6 on my server as python 3.7 was giving me too many issues. Unfortunately instead of showing up as python3 executable it is only python. here is the results of dir:
aclocal.m4 config.sub Include Mac Modules Programs Python setup.py
build configure install-sh Makefile Objects pybuilddir.txt python-config Tools
config.guess configure.ac Lib Makefile.pre Parser pyconfig.h python-config.py
config.log Doc libpython3.6m.a Makefile.pre.in PC pyconfig.h.in python-gdb.py
config.status Grammar LICENSE Misc PCbuild python README.rst
I have edited the env path to go to this directory
[root#server]# echo $PATH
/usr/src/Python-3.6.6/python:$PATH
and even
/usr/src/Python-3.6.6/
but obviously that wouldn't work because the python3 command doesn't even exist in the directory. I tried renaming python to python3 so it would run it. Currently the server came with python 2.6.6 and I don't want to disturb that version as I only need this for one piece of software. Though I need to use pip3 and if the system can't find python3 then pip3 command is also not found. Would it have to do with this install process?:
./configure --enable-optimizations --enable-loadable-sqlite-extensions
make altinstall
I wasn't sure if the make altinstall was screwing with it but.
python -3 -m ....
Or
py -3 -m ....
Anything wrong these?
[EDIT]
Further to your comment, it sounds like it could be one of the following:
The file you're trying to use is not in the PATH variable.
https://askubuntu.com/questions/60218/how-to-add-a-directory-to-the-path
Python 3.6 is not in its default position after installation or has been renamed after installation.
Where possible, and practicable, if you're unsure, then ALWAYS install with the relevant installation tool, e.g. apt-get. As far as I'm aware, this will automatically add the directory for Python to the $PATH variable. You can also type that variable into the CLI if you really want to manually check it is 100% in the PATH.

easy_install prefix option does not work

# 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

pip install on Mac OS X - PYTHONPATH

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?

install a library for python

i'm trying to install a library for python of gene ontology programming [GOGrapher]. In the page they told me this:
$ `svn co https://projects.dbbe.musc.edu/public/GOGrapher/trunk GOGrapher`
$ cd GOGrapher
$ su -
# python setup.py install
I do everything, but in the last step a get an error
error: /usr/local/lib/python2.7/dist-packages/GOGrapher-0.0.egg-info: Permission denied
What is wrong? I'm new on this, but I do what I can.
Try
sudo python setup.py install
instead. (Works for me on Mac OS 10.7.3, while the suggested su - solution doesn't).
It is not a good idea to install things as superuser in the filesystem. In Python you can always install libraries locally.
Assuming you are already in GOGrapher directory:
$ python setup.py install --home
should install the library in your home directory. Later, you have to add the library PATH to the PYTHONPATH environment variable, so Python will know where to search for it.
$ export PYTHONPATH=$HOME/lib/python
The directory might be slightly different (lib/python2.7 or even lib/python2.7/site-packages), you can check it, tough.
To make it permanent, you should add it in your .profile, .bashrc, or whatever is the shell you are using.

Categories

Resources