I am trying to install setuptools via an egg on my VPS. However, I keep getting an error that Python2.6 doesn't exist despite the fact that it is in $PATH:
[root#host install]# sudo sh setuptools-0.6c11-py2.6.egg
setuptools-0.6c11-py2.6.egg: line 3: exec: python2.6: not found
[root#host install]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib/courier-imap/sbin:/usr/lib/courier-imap/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/wt_python/bin
[root#host install]# sudo /usr/local/wt_python/bin/python2.6
Python 2.6.5 (r265:79063, May 18 2010, 16:49:22)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
[root#host install]# sudo python2.6
Python 2.6.5 (r265:79063, May 18 2010, 16:49:22)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
Any idea what could be wrong?
Thanks
1 ) sudo as root is redundant.
2 ) for a quick hack symlink your python install into a standardized path. I'm not 100% familiar with the setuptools installer, but it could spawn a subshell that would mess with environment variables. For that matter sudo depending on flags messes with environment variables.
3) If there isnt a reason why you specifically need a custom python build why not use the one in the repositories?
Hope one or a few of the ideas help.
Rob
Related
I I'm trying to use python with conda environment.
I create an environment using
conda create -n new_env3 python=3.9
Then when I start python terminal (just running 'python') I get:
Python 3.9.12 (main, Apr 5 2022, 06:56:58)
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
Segmentation fault
I tried multiple python versions and sub-versions, but all resulted in the same error
i met the same problem, and conda clean -a didn't solve the problem
$ python
Python 3.10.6 (main, Oct 24 2022, 16:07:47) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
Segmentation fault
Try running conda clean -a.
This will remove all unused packages.
I have installed python 3.8.0 via pyenv.
pyenv which python
/Users/myname/.pyenv/versions/3.8.0/bin/python
If I run python3 I get
python3
Python 3.6.8rc1 (v3.6.8rc1:cc3e73212a, Dec 11 2018, 17:37:34)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
If I check
which python3
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3
How can I set the 3.8.0 version as default?
By typing pyenv global 3.8
You check get the list of options by typing pyenv -h
If you have multiple versions of python installed, you can do python -3.x -m ...
Also check if the env is active before opening it.
I installed Anaconda in a Google Cloud Compute environment and can use it successfully from the shell as a normal user:
curt#lamp-v5mi:~$ python
Python 2.7.9 |Anaconda 2.2.0 (64-bit)| (default, Mar 9 2015, 16:20:48)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
However, when I start an interpreter via sudo python, anaconda is not the interpreter used, and I would like it to be.
curt#lamp-v5mi:~$ sudo python
Python 2.7.3 (default, Mar 13 2014, 11:03:55)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Confusingly, when I start a shell as root and then start an interpreter, anaconda is the interpreter used.
curt#lamp-v5mi:~$ sudo -s
root#lamp-v5mi:/home/curt# python
Python 2.7.9 |Anaconda 2.2.0 (64-bit)| (default, Mar 9 2015, 16:20:48)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
I have export PATH="/anaconda/bin:$PATH" in both the root's and my normal account's .bashrc files. At first I thought the issue was sudo python not actually starting a root shell, and thus the export PATH="/anaconda/bin:$PATH" not actually being done. But when from my normal account I do sudo echo $PATH, it shows anaconda in there:
curt#lamp-v5mi:~$ sudo echo $PATH
/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
The anaconda installation was installed as root in /anaconda and I did a chmod -R 770 /anaconda to make it accessible to normal users, but I don't think this problem has anything to do with that.
How can I get anaconda to be the default interpreter when run from a sudo command line?
You almost got everything right. The only error is sudo echo $PATH, where $PATH is substitued BEFORE being sent to sudo, so it's your user PATH not your "sudoed" PATH that's displayed.
Note that your sudo implementation and configuration may change the PATH variable, as I can read in a "man sudo" (found from the Internet as I don't have sudo):
PATH
May be overridden by the security policy.
So, in your "sudoed" PATH, there's probably no /anaconda/bin/
You may test this using sudo env | grep PATH.
To allow or change the PATH environment variable in your sudoed environment, I only can direct you to your man sudo, again: I'm not a sudo user.
The only thing I can drop you is sudo $(which python), as in sudo echo $PATH, the $(which python) will be executed by your user, resulting in /anaconda/bin/python, so actually running sudo /anaconda/bin/python which is another "solution".
To conclude, I should warn you that you probably don't want to run Python as root, there is almost no valid reason to do this, so your question is probably an XY problem: You got a first problem, you concluded by yourself it can be resolved by running Python as root, you tried sudo, got hit by sudo changing your PATH, then posted your "2nd level" problem here. What is your "real problem" ? The one that triggered the "Hum, I should try with sudo" ?
I am a non-superuser of a linux machine.
Currently it has 2 versions of Python.
When I invoke standard python command it gave version 2.6
$ python
[neversaint#mach71 ~]$ python
Python 2.6.2 (r262:71600, Jan 28 2011, 13:47:39)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
$ which python
/opt/somedir/bin/python
It's only when I invoke with python2.7 it gives the version 2.7
[neversaint#mach71 ~]$ python2.7
Python 2.7.6 (default, Nov 11 2013, 13:13:15)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
$ which phython2.7
/usr/bin/python2.7
My question is how can I set it such that whenever I call $ python it will give me version 2.7.
You can simlink it into some directory both accessible to your user and in your $PATH. For example if /home/<your-username>/local/bin is in your $PATH then you can do
ln -s /usr/bin/python2.7 /home/<your-username>/local/bin/python
In this example /home/<your-username>/local/bin should be in your path before /usr/bin. If there is no such entry in your $PATH you can add it there:
export PATH=$HOME/local/bin:$PATH
You can also add this line to .bashrc or similar to activate it on shell start.
Use a shell alias, alias python=/usr/bin/python2.7 and then python will execute the result of that alias.
in /usr/bin create symlink to python27 or whatever python version you have
sudo ln -s python2.7 python
I'm trying to use a newer Python (2.7.3) with an old CentOS.
I have a recipe to install python to a non-standard location:
./configure --prefix=#{install_path} --with-threads --enable-shared --with-zlib=/usr/include
make
make install
I set the PATH and LD_LIBRARY_PATH variables to find bin/python and the .so files using /etc/profile.d/. This seems to mostly work.
With a non-root user, I get the right Python:
[vagrant#localhost ~]$ python
Python 2.7.3 (default, Dec 24 2012, 15:18:59)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
With a root user, I get the right Python:
[vagrant#localhost ~]$ sudo su
[root#localhost vagrant]# python
Python 2.7.3 (default, Dec 24 2012, 15:18:59)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
However, the $LD_LIBRARY_PATH hack seems to be a little wonked when using sudo:
[vagrant#localhost ~]$ sudo python
python: error while loading shared libraries: libpython2.7.so.1.0:
cannot open shared object file: No such file or directory
Even though the variables look right:
[vagrant#localhost ~]$ sudo which python
/opt/Python-2.7.3/bin/python
Adding Defaults env_keep += "LD_LIBRARY_PATH" to /etc/sudoers does not work.
sudo -i python does work.
sudo -E python does not work.
I'm curious what I could do to get sudo to pick up the right Python without -i?
related:
sudo changes PATH - why?
https://stackoverflow.com/questions/12593336/odd-path-behaviour-on-centos-python
Thanks to this blog post. You can forego the use of $LD_LIBRARY_PATH by linking with LDFLAGS in configure. Where #{ldlibpath} is #{install_path}/lib:
./configure --prefix=#{install_path} --with-threads --enable-shared \
--with-zlib=/usr/include LDFLAGS="-Wl,-rpath #{ldlibpath}"
As noted in the blog post, you will need to mkdir this ldlibpath before running configure.