I accidentally downloaded python2.6.6 on my centos Virtual Machine from python.org's official download package and compiled it to source.
Now in my /usr/local/bin I have a python2.6 shell available and now if I use which python it will give me the path of /usr/local/bin instead of original python2.7's path which is /usr/bin.
Since I installed it from source, yum doesn't recognise python2.6.6 as a package and I want to get rid of it.
If I do rpm -q python it gives me a result of python-2.7.5-48.0.1.el7.x86_64
Is it possible to uninstall python2.6.6 and I will just re-point my python system variable to /usr/bin again?
Sure, but you'll have to do it the hard way. Dig through /usr/local looking for anything Python-related and remove it. The python in /usr/bin should be revealed once the one in /usr/local/bin is removed.
Also, next time make altinstall. It will install a versioned executable that won't get in the way of the native executable.
Related
I am on an Ubuntu machine, where Python 3.10 is automatically installed. To do a given task in a shared codebase I need to use Python 3.9 for some issues with new versions.
I would like to have both of the Python installed on my machine and be able to use both and switching if I need to.
So, I am trying to install old Python 3.9 with the command sudo apt-get install python3.9 and it succeeded in installation, but I can't find it anywhere even with which python3.9 and similar.
Even the python interpreter option in VSCode does not show it.
I think I am missing something. Can please someone help me? Thank you
Python should be installed under the /usr/bin/ folder. If it's not there, you might have not actually installed the package.
Check out this guide for installing specific versions (Scroll down to the "Use Deadsnakes PPA to Install Python 3 on Ubuntu" section.)
This will allow you to install specific version of python like python3.9
Packages on Ubuntu (usually executables) are installed in the /usr/bin directory. You could try to list all executables under /usr/bin with
ls /usr/bin/python*
This is the easiest way. You could see also what packages are installed
apt list --installed | grep python
I just upgraded to python 3.7 and I realized that all my modules stuck with the previous version. Even Django is not recognised anymore. How can I do to transfer everything to the new version? I am a little lost right now, don't even know where the new version has been installed.
Edit:
When I do $ which python3.6 the terminal tells me it doesn't exist, but I have a python3.6 directory in /usr/local/lib/, where all modules are installed.
In the same directory /usr/local/lib/ I also have a python3.7 directory with some modules installed but many are missing. However when I search for the file python3.7 in my finder it doesn't appear. when I do $ which python3.7 the path is /usr/local/bin so not the same path as the directory.
Anyone sees what happened and knows how I can transfer all modules to python3.7?
Even if the old python version has been removed, it is possible to use the pip of the current python version with the --path option to list all the modules installed in the previous version.
For example, migrating all my user installed python modules from 3.7 to 3.8
pip freeze --path ~/.local/lib/python3.7/site-packages > requirements.txt
pip install --user -r requirements.txt
Incidentally, I always use pip install with --user and leave the system wide installations to the package manager of my linux distro.
It is safer to re-install all packages due to possible compatibility issues:
pip3.6 list | awk '{print $1}' | xargs -I{} pip3.7 install {}
in older version of Python --run the command
pip freeze > requirements.txt
download and install newer version on python.. change the PATH variable to the new version
and run the command
pip install -r requirements.txt
I'm not sure about all modules...but if you want to install a module specifically in python3.7, try this:
python3.7 -m pip install *module_name*
In some cases, we don't have the opportunity to pip freeze in old version--because I've already updated and old version have been purged! There are some measures I've taken to recover some of the packages but I'm NOT sure every package would work with this fix.(e.g. the packages built with wheels)
mv /your/path/to/python3.{6,7}/site-packages/
If the case is packages installed outside venv (in /usr/local/ or ~/.local), reinstall pip with get-pip.py, just to be safe.
If you are recovering a virtualenv. Activate your virtualenv and use my script
Most of your packages should work by now. If anything malfunctions, pip reinstall would works. If you still want it 100% works, pip freeze now.😉
I have an alternative
(Not sure if works outside Windows 10)
I'm currently migrating from 3.7 to 3.8 and the way I found to re-install my previous libraries was by using a script I had that updates all packages via pip install. (Assuming you installed your new Python version as your main version) This checks for all the packages I had and updates/install them in the new Python version.
Note: I prefer to run the script from the command line
Use the file explorer to go to the folder where you have the script;
Click on the path box, write "cmd" and press enter to open a command line from the folder where you are;
Write "python name_of_your_script.py" and press enter to run the command.
The script (adapted from this solution):
import pkg_resources
from subprocess import call
packages = [dist.project_name for dist in pkg_resources.working_set]
[call("pip install " + name + " --upgrade") for name in packages]
I faced a similar problem, now that I upgraded from python 3.7 to python 3.8 (new)
I installed Python 3.8, but the system kept the python37 subfolder with the already installed packages(...\Python37-32\Lib\site-packages) even with the Pyhton38 subfolder created, with the new python.exe.
Usually, it's possible to keep on using the old libraries on your new Python version, because the existent libraries installation folder are already registered in your local computer system path (*).
Even though, I've had problems to use some libraries (some worked in Jupyter Notebook but not in Spyder). I tried the alternatives others proposed to migrate libraries but it did not worked (maybe I did not
So I used brutal force solution.. Not elegant at all, but it worked:
remove the OLD python version folders from the system path or even remove the folder itself for good..
Folders: C:\Users\USERNAME\AppData\Roaming\Python\Python37
C:\Users\USERNAME\AppData\Local\Programs\Python\Python37
Reinstall the packages you need, preferably via Anaconda prompt.
python -mpip install library_name
OR
pip install --user --force-reinstall package_name
OR
pip install --user --force-reinstall package_name == specify_package_version
The libraries will be installed at c:\users\USERNAME\anaconda3\lib\site-packages and recognized by your new python version.
(*) to add the folder to the PATH: System properties --> environment variables --> click "Path"--> edit --> add folder name)
I have tried to install libraries using pip but my console doesnt recognize as a command. I checked the python/scripts folder and there was no ppip.exe in the folder. I reinstalled Python 3.6 a couple of times but I havent been able to use it. I tried it on another computer and pip installed itself with python 3.6.
I've seen answers that say to open a Python shell, then insert
python -m pip install 'packagename'
but i tried this and the shell marked invalid syntax at the end of writing pip
on linux(ubuntu)
#for default
sudo apt install python-pip
#for version specific
python2.7
sudo apt install python2-pip
for 3.x
sudo apt install python3-pip
for windows
In some terminals try to use
$py -m pip install packagename
Of course you first have to import pip with
$import pip
if pip is installed the following will work for sure
open a python shell then
import pip
pip.main(['install', 'packagename'])
replace the packagename with the package you want to install
because of the path problem try to use absolute paths ( in windows beginning with drive letter i.e. C:/.../.../pip.exe). in batch script it is generally good idea to use absolute paths. Alternatively check if your path has to be fixed : https://docs.python.org/3/using/windows.html
( http://jelly.codes/articles/python-pip-module/ )
Operating systems search for executables in the system path. I.e. windows knows by default where its own executables are located because the directory is in the system path, however when new software is installed that contains executables like pip the system path has to be edited to inform windows ( or linux ) where the new executables are located. The path is an environment variable. This is also valid for other languages and programs like java ( Environment variables for java installation ) ,...
Now your problem very likely is that the directory where the pip.exe executable is stored is not part of your windows path. This has to be fixed like in https://docs.python.org/3/using/windows.html, chapter 3.3. Configuring Python
How to run Pip commands from CMD
I am running Debain 8 Jessie and have installed python 2.7.13 into /usr/local/bin.
I do not have a new pip installed, I am still using the pip located at /usr/bin/. Any time I install a package using pip, they are installed to the dist-packages location of my new python install:
/usr/local/lib/python2.7/dist-packages
Question
How do I get my pip installs to permanently install in /usr/lib/python2.7/dist-packages? What is even weirder, is that although these packages are installing to a location seemingly setup by my new install, I cannot import whatever I download when I am using python2.7.13 via /usr/local/bin/python.
PATH
/usr/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin:/sbin:/bin:
Better Yet
How do I just get my python2.7.13 install to see the installed packages from pip?
Run this:
import sys
for p in sys.path:
print p # or print(p) if you prefer.
Look for /usr/lib/python2.7
if not you'll want to
export PYTHONPATH=/usr/local/lib/python2.7:/usr/lib/python2.7
in .bashrc or in a special (host-wide) script in /etc/profile.d/
If /usr/lib/python2.7/
Depending on the difference between your "stock" version and 2.7.13, you might not want to put stuff in /usr/lib/python2.7. On my system I'd really want to avoid any cross contamination, but that's something I'm a bit picky about.
On my Fedora11 machine which has python2.6 pre-installed on it, I was able to successfully install python 2.7 using the following steps:
wget http://www.python.org/ftp/python/2.7/Python-2.7.tar.bz2
tar -xvjf Python-2.7.tar.bz2
cd Python*
./configure --prefix=/opt/python27
make
make install
vi ~/.bash_profile
## replaced PATH=$PATH:$HOME/bin
## with PATH=$PATH:$HOME/bin:/opt/python27/bin
## reload .bash_profile
source ~/.bash_profile
echo "/opt/python27/lib" > /etc/ld.so.conf.d/python27.conf
ldconfig
However, when I checked the python version the system uses via terminal (python -V), it still shows python 2.6.
How will I make the system use python2.7 as its default python?
Or if possible, how will I uninstall python2.6?
Thanks in advance!
Uninstalling the system Python is a bad idea. There are many other packages and softwares that depend on it. It'll be better that you use python2.7 by either modifying the $PATH or creating an alias e.g. python2.7 that points to the python that you installed in /opt dir.
Uninstalling fedora-provided python 2.6 might break many packages that depend on it. I advise you against doing it.
Now, your problem is simply that $PATH and similar variables ($MAN_PATH etc.) are searched from left to right. You appended your new /opt/python27/bin after standard locations like /usr/bin. Reverse the order, and you will get /opt/python27/bin/python as a default python binary.
First of all - never ever try to uninstall Python on RHEL/CentOS/Fedora. yum is written in Python and there will be many problems with repairing the system.
If you want the system to use Python2.7 by default, find where the Python2.6 (use whereis python or which python commands) binary is located, backup it and replace with the binary of Python2.7
Instead of uninstall older version, use specific version of python while using it
I changed symbolic link
ln -s /usr/local/bin/python2.7 /usr/local/bin/python
And used
python -m pip install pip --upgrade
Or you can simply use Yum feature of linux & run command yum remove python it will delete python & related dependencies from the system