I'm new for linux and python ,yesterday I update my python from 2.6.6 to 2.7.13,but when i finished these command "./configure 、make、make install " ,then run "python“ ,I got "command not found ". thanks for help
I completely agree with the answer provided by #holdenweb. Just to add some more details considering for a tyro:
If you need access to a newer version of Python you must compile it yourself and install it side-by-side with the system version.
Here are the steps necessary to install Python 2.7. Execute all the commands below as root. Either log in as root temporarily or use sudo.
Install development tools
In order to compile Python you must first install the development tools:
The first one is :
yum groupinstall "Development tools"
You also need a few extra libraries installed before compiling Python or else you will run into problems later when trying to install various packages:
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel
Download, compile and install Python
The --no-check-certificate is optional
cd /opt
wget --no-check-certificate https://www.python.org/ftp/python/2.7.6/Python-
2.7.6.tar.xz
tar xf Python-2.7.6.tar.xz
cd Python-2.7.6
./configure --prefix=/usr/local
make && make altinstall
It is important to use altinstall instead of install, otherwise you will end up with two different versions of Python in the filesystem both named python.
After running the commands above your newly installed Python 2.7 interpreter will be available as /usr/local/bin/python2.7 and the system version of Python 2.6.6 will be available as /usr/bin/python and /usr/bin/python2.6.6.
Now Python is an essential component of many operating systems, the safest rule is leave the system's Python to the system, and don't modify it yourself. That way you can be sure you aren't going to interfere with any OS code that depends on a specific version of Python.
If you want some other version of Python to be your own default, install it somewhere like /usr/local/bin (the default installation for most Linux systems will put it there by default) and then put that directory at the front of your shell's PATH to ensure that the python command gets your version instead of the system's (which will remain as /usr/bin/python).
I would recommend that you re-link /usr/bin/python to point to /usr/bin/python2.6 and then the PATH adjustment mentioned above (but in your case adding /usr/local/python2.7.13/bin, which is where you seem to have installed your updated Python) should be all you need to do.
Related
As Python 3.7 was being prepared I installed Python 3.7.0b3 from source. Now 3.7 is out and I want to use the version packaged for Ubuntu. So I've done
apt-get install python3.7
but
$ which python3.7
/usr/local/bin/python3.7
$ /usr/local/bin/python3.7 --version
Python 3.7.0b3
How does one uninstall a Python installed from source (on Ubuntu)?
Or how can I replace it with the apt repo packaged version?
Since you opened a bounty, I can't vote to close as a duplicate, but this question would seem to provide a possible solution. Quoting from the accepted answer:
You can use checkinstall to remove Python. The idea is:
Install checkinstall
Use
checkinstall to make a deb of your
Python installation
Use dpkg -r to
remove the deb.
checkinstall basically wraps a make install command and creates a Debian .deb package based on what was installed. Then, you can just uninstall that package to reverse make install completely. To be perfectly safe you may want to uninstall the packaged Python 3.7 first and reinstall it afterwards to avoid any conflicts (I wouldn't expect any, though, since the packaged version lives in /usr while your source version lives in /usr/local).
If you don't have your source files around anymore, you can always download them again (https://www.python.org/downloads/release/python-370b3/) and rebuild Python. Specifically, the checkinstall commands would look something like this:
sudo apt install checkinstall
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0b3.tgz
tar xf Python-3.7.0b3.tgz
cd Python-3.7.0b3
./configure && make
sudo checkinstall -D --fstrans=no make install
sudo dpkg -r Python-3.7.0b3.deb
(-D creates a Debian package, --fstrans=no disables use of a temporary directory for installation).
Since I was also moving to python 3.7, I came across this question and decided to answer it, as well as finish my installation.
This are the two sources, which I used for installing python 3.7 on ubuntu 16.04:
https://askubuntu.com/questions/865554/how-do-i-install-python-3-6-using-apt-get
https://superuser.com/questions/241865/updating-python-on-ubuntu-system
Apparently from the first source the deadsnakes PPA contain Python 3.7 - Link: https://github.com/deadsnakes/python3.7/tree/ubuntu/xenial/Python
So following from my first source, I used the following commands to install Python 3.7:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.7
It installed Python 3.7 successfully but my Python 3.5.2 remains default. You can invoke/use Python 3.7 by running the commands:
python3.7 script.py
It works, so I decided to set Python 3.7 as default by removing python 3.5, but I came across my second source, and just decided to stick with using python3.7, when running my script in the terminal.
Apparently it says:
Ubuntu policies extensively for writing end-user software. So basically, a large part of the system is written in Python. To switch to Python 3.7, there needs to be done a piece of work consisting of updating and re-testing all the scripts.
So to say you can't just switch to Python 3.7 and delete the older version.
Also from a comment from my first source it states deleting the older version might break the system. I haven't been around to deleting my older version in case it might break the system, but since you are asking for how to download Python 3.7, I think my first source and the first part of my answer should to the work.
I hope it helps :)
It seems that your Python built from source is under /usr/local, and your PATH variable has /usr/local/bin before /usr/bin, since running python3.7 gets you the one under /usr/local rather than the packaged one which would be /usr/bin/python3.7.
Look at your PATH to verify this.
echo $PATH
(When you run a program in bash, that particular running bash instance will remember the location and not rescan the directories in the PATH for that program again, so it will not notice a new file that has appeared somewhere earlier in the PATH. You can prevent this by running hash -r to reset the cache or by just exiting the shell and launching it again.)
I presume your goal is for python3.7 (or any of the other commands provided by Python) to run the versions from your packaged install in /usr.
Unfortunately the python build process does not provide an uninstall method -- the only automated way to remove just the files installed by a source Python install requires using other tools ahead of time (such as checkinstall).
So you have some choices :
Change your PATH so that /usr/local/bin is after /usr/bin. To do this, edit your ~/.profile file or whatever other script you have configuring your PATH and logout/login. This will also affect any other commands you run that are available in both /usr/local/bin and /usr/bin.
Remove /usr/local and reinstall anything else you want there. If a Python install is the only thing in your /usr/local, or if you can easily reinstall anything else you had there, this might be the way to go.
Painstakingly figure out what files under /usr/local/bin were part of Python and remove them. You might be able use the corresponding files in /usr/bin from your installed python3 packages as a starting point to figure out the similar names for /usr/local/bin.
One-liner to get the list of files in /usr/bin from installed python3* packages:
$ for pkg in $(dpkg -l 'python3*' | grep '^ii' | cut -f 3 -d' '); do dpkg -L $pkg | grep '^/usr/bin/'; done | sort
This should produce a list of files like:
/usr/bin/2to3-3.x
/usr/bin/chardet3
...
(I've tested this one-liner on Debian, I'm not sure if any changes are required for Ubuntu)
I have an older version of Openssl that I no longer want to use with python3.4 programs. I have been using the following configure options
./configure CPPFLAGS="-I~/Downloads/openssl/1.0.1j/include" LDFLAGS="-L~/Downloads/openssl/1.0.1j/lib"
After compiling I print the openssl version from within a python program it will show the older version and not the one I have linked to above.
Are there other options I need to specify or do I need to alter setup.py?
You need to set CPPFLAGS and LDFLAGS before running ./configure. So, from the command line, (assuming you're using bash or similar):
$ export CPPFLAGS="-I~/Downloads/openssl/1.0.1j/include"
$ export LDFLAGS="-L~/Downloads/openssl/1.0.1j/lib"
$ ./configure
$ python3 setup.py make
$ sudo python3 setup.py install # assuming you have admin rights
Obviously, make sure you have successfully compiled openssl first, as just unzipping the source won't work. If you don't have admin access, or just choose to install everything in your home directory, I find it easier to create ~/lib and ~/include directories along with ~/bin so everything can be stored in one place.
My question is much like several others. Having manually compiled Python, sqlite3 is missing:
The main difference is that I'm using a Debian Linux system (unlike in this question: OS X 10.8.2 python 3 import sqlite error), and Python3 (unlike in this and a bunch of other questions: Cannot import SQLite with Python 2.6).
I was hoping for some guidance on which direction to troubleshoot in. According to some of the Linux-but-older-Python questions, an error like the one I'm getting could be caused by a missing resource during linking or something (_sqlite3.so). I have two such files on my system, both of them in older Python installations, ... but nothing related to Python3. Or is one of these good enough? Or they say to install the libsqlite3-dev package, then to re-compile Python. I did this, but I don't see how just having this package on my system will affect the compilation process. And indeed, it didn't. A second compile gave me a second Python without sqlite3.
I wish I could just do apt-get install python3, but Debian, in its stability, only has Python 3.2, where I need the latest version. Thoughts?
You need to install libsqlite3 (Debian based) or sqlite-devel (RedHat based) and the associated header files before compiling Python because Python needs to find them during the compile process.
Did you make sure to run:
./configure
make
make install
In this specific order? With no missing steps?
After apt-get install libsqlite3-dev
then
./configure --prefix=/opt/python3.7.4 --with-ssl --with-pydebug
make
make install
Note: You might need apt-get install libssl-dev aslo, openssl version must above 1.0.2 if you are compiling python3.7
For me, I'm using ubuntu 14.04 (trusty) I can't find a libssl-dev package to meet the requirement compiling python3.7 with ssl support. I modify my /etc/apt/sourcelist.d
deb http://cn.archive.ubuntu.com/ubuntu/ xenial main restricted
deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial main restricted
after install a newer libssl-dev, then change it back to the original one
deb http://cn.archive.ubuntu.com/ubuntu/ trusty main restricted
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty main restricted
If you only have limited user access (no root or sudo permission) you can install to a local, user accessible, environment like so:
tar -xvf sqlite-autoconf-3270200.tar.gz
cd sqlite-autoconf-3270200
./configure --prefix=$HOME/.local
make && make install
This will install on your ~/.local tree.
Add ~/.local/bin to your path if missing.
I recently installed Python 2.7.3 on a CentOS machine by compiling from source. Python 2.7.3 is installed at /opt/python2.7 and when I installed it I just changed /usr/bin/python to point to the new version. This apparently is wrong though because when I did it it broke yum. I would get the following.
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
No module named yum
Please install a package which provides this module, or
verify that the module is installed correctly.
It's possible that the above module doesn't match the
current version of Python, which is:
2.7.3 (default, May 15 2012, 17:45:42)
[GCC 4.4.4 20100726 (Red Hat 4.4.4-13)]
If you cannot solve this problem yourself, please go to
the yum faq at:
http://yum.baseurl.org/wiki/Faq
I changed /usr/bin/python to point back to the python 2.6.6 but now 2.6.6 is the default version of python. Any idea how to fix this?
I have written a quick guide on how to install the latest versions of Python 2 and Python 3 on CentOS 6 and CentOS 7. It currently covers Python 2.7.13 and Python 3.6.0:
# Start by making sure your system is up-to-date:
yum update
# Compilers and related tools:
yum groupinstall -y "development tools"
# Libraries needed during compilation to enable all features of Python:
yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel expat-devel
# If you are on a clean "minimal" install of CentOS you also need the wget tool:
yum install -y wget
The next steps depend on the version of Python you're installing.
For Python 2.7.14:
wget http://python.org/ftp/python/2.7.14/Python-2.7.14.tar.xz
tar xf Python-2.7.14.tar.xz
cd Python-2.7.14
./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
make && make altinstall
# Strip the Python 2.7 binary:
strip /usr/local/lib/libpython2.7.so.1.0
For Python 3.6.3:
wget http://python.org/ftp/python/3.6.3/Python-3.6.3.tar.xz
tar xf Python-3.6.3.tar.xz
cd Python-3.6.3
./configure --prefix=/usr/local --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
make && make altinstall
# Strip the Python 3.6 binary:
strip /usr/local/lib/libpython3.6m.so.1.0
To install Pip:
# First get the script:
wget https://bootstrap.pypa.io/get-pip.py
# Then execute it using Python 2.7 and/or Python 3.6:
python2.7 get-pip.py
python3.6 get-pip.py
# With pip installed you can now do things like this:
pip2.7 install [packagename]
pip2.7 install --upgrade [packagename]
pip2.7 uninstall [packagename]
You are not supposed to change the system version of Python because it will break the system (as you found out). Installing other versions works fine as long as you leave the original system version alone. This can be accomplished by using a custom prefix (for example /usr/local) when running configure, and using make altinstall (instead of the normal make install) when installing your build of Python.
Having multiple versions of Python available is usually not a big problem as long as you remember to type the full name including the version number (for example "python2.7" or "pip2.7"). If you do all your Python work from a virtualenv the versioning is handled for you, so make sure you install and use virtualenv!
vim `which yum`
modify #/usr/bin/python to #/usr/bin/python2.4
Put /opt/python2.7/bin in your PATH environment variable in front of /usr/bin...or just get used to typing python2.7.
pythonz, an active fork of pythonbrew, makes this a breeze. You can install a version with:
# pythonz install 2.7.3
Then set up a symlink with:
# ln -s /usr/local/pythonz/pythons/CPython-2.7.3/bin/python2.7 /usr/local/bin/python2.7
# python2.7 --version
Python 2.7.3
ln -s /usr/local/bin/python2.7 /usr/bin/python
Alright so for me, the error being fixed is when there are different versions of python installed and yum can't find a certain .so file and throws an exception.
yum wants 2.7.5 according to the error.
which python gives me /usr/bin/python
python --version gives me 2.7.5
The fix for me was append /lib64 to the LD_LIBRARY_PATH environment variable.
The relevant content is /lib64/python2.7 and /lib64/python3.6.
export LD_LIBRARY_PATH=/lib64:$LD_LIBRARY_PATH
Fixed the yum error for me with multiple python versions installed.
Daniel's answer is probably the most ideal one as it doesn't involve changing OS files. However, I found myself in a situation where I needed a 3rd party program which invoked python by calling usr/bin/python, but required Python 2.7.16, while the default Python was 2.7.5. That meant I had to make usr/bin/python point to a Python version of 2.7.16 version, which meant that yum wouldn't work.
What I ended up doing is editing the file /usr/bin/yum and replacing the shebang there to use to the system default Python (in my case, that meant changing #! /usr/bin/python to #! /usr/bin/python2). However, after that running yum gave me an error:
ImportError: No module named urlgrabber.grabber
I solved that by replacing the shebang in /usr/libexec/urlgrabber-ext-down the same way as in /usr/bin/yum. I.e., #! /usr/bin/python to #! /usr/bin/python2. After that yum worked.
This is a hack and should be used with care. As mentioned in other comments, modifying OS files should be last resort only.
I recommend, instead, updating the path in the associated script(s)
(such as /usr/bin/yum) to point at your previous Python as the interpreter.
Ideally, you want to upgrade yum and its associated scripts so that they
are supported by the default Python installed.
If that is not possible, the above is entirely workable and tested.
Change:
#!/usr/bin/python
to whatever the path is of your old version until you can make the
above yum improvement.
Cases where you couldn't do the above are if you have an isolated machine,
don't have the time to upgrade rpm manually or can't connect temporarily
or permanently to a standard yum repository.
If you want to try out rpm packages, you can install
binary packages based on the newest Fedora rpms, but recompiled
for RHEL6/CentOS6/ScientificLinux-6 on:
http://www.jur-linux.org/download/el-updates/6/
best regards,
Florian La Roche
I read a piece with a comment that states the following commands can be run now. I have not tested myself so be careful.
$ yum install -y epel-release
$ yum install -y python36
I extracted, configured and used make for the installation package in my server.
However, I could not use make install. I get the error
[~/wepapps/python/Python-2.6.1]# make install
/usr/bin/install -c python /usr/local/bin/python2.6
/usr/bin/install: cannot create regular file `/usr/local/bin/python2.6': Permission denied
make: *** [altbininstall] Error 1
I run the folder with
chmod +x Python-2.6.1
I get still the same error.
How can I run make install without sudo access?
How can I install to a path under my home directory?
mkdir /home/masi/.local
cd Python-2.6.1
make clean
./configure --prefix=/home/masi/.local
make
make install
Then run using:
/home/masi/.local/bin/python
Similarly if you have scripts (eg. CGI) that require your own user version of Python you have to tell them explicitly:
#!/home/masi/.local/bin/python
instead of using the default system Python which “#!/usr/bin/env python” will choose.
You can alter your PATH setting to make just typing “python” from the console run that version, but it won't help for web apps being run under a different user.
If you compile something that links to Python (eg. mod_wsgi) you have to tell it where to find your Python or it will use the system one instead. This is often done something like:
./configure --prefix=/home/masi/.local --with-python=/home/masi/.local
For other setup.py-based extensions like MySQLdb you simply have to run the setup.py script with the correct version of Python:
/home/masi/.local/bin/python setup.py install
As of year 2020, pyenv is the best choice for installing Python without sudo permission, supposing the system has necessary build dependencies.
# Install pyenv
$ curl https://pyenv.run | bash
# Follow the instruction to modify ~/.bashrc
# Install the latest Python from source code
$ pyenv install 3.8.3
# Check installed Python versions
$ pyenv versions
# Switch Python version
$ pyenv global 3.8.3
# Check where Python is actually installed
$ pyenv prefix
/home/admin/.pyenv/versions/3.8.3
# Check the current Python version
$ python -V
Python 3.8.3
Extending bobince answer, there is an issue if you don't have the readline development package installed in your system, and you don't have root access.
When Python is compiled without readline, your arrow keys won't work in the interpreter. However, you can install the readline standalone package as follows: Adding Readline Functionality Without Recompiling Python
On the other hand, if you prefer to compile python using a local installation of readline, here's how.
Before doing as bobince was telling, compile and install readline. These are the steps to do so:
wget ftp://ftp.cwru.edu/pub/bash/readline-6.2.tar.gz
tar -zxvf readline-6.2.tar.gz
cd readline-6.2
./configure --with-prefix=$HOME/.local
make
make install
Then, add this line to your .bash_profile script:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/.local/lib
Last, but not least, execute the following command
export LDFLAGS="-L$HOME/.local"
I hope this helps someone!
You can't; not to /usr, anyway. Only superusers can write to those directories. Try installing Python to a path under your home directory instead.