Too Many versions of python on my computer - python-3.x

I have too many versions of python on my computer. And, when I try to run my code, my module like pandas, selenium, etc said this error message:
ModuleNotFoundError: No module named 'pandas'.
I have pip and conda install everything but neither version of python works when I choose each of them in VS Code interpreter.
Do you have a solution to uninstall each version of python?
Command prompt:

You need to define the versions of python
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2
Then you need to choose which version should be defined as default
sudo update-alternatives --set python /usr/bin/python3.6
Alternatively, try pyenv pyenv to manage your python versions.

just type Apps and Features in you pc's search bar and uninstall every version of python you see there and re install the one that you need

#Sagar mochi. Thanks for your answer. I have been searching for and trying different solutions all day. Your solution worked for me :)

Related

Installed python package with `pip3`, but when I call it I get "No module named X"

I installed a module like this:
> pip3.8 install mssql-cli
but when I run it I get:
> 3002 ~$ mssql-cli -S 192.168.7.50 -d test-db
/usr/bin/python: No module named mssqlcli
I think mssql-cli is defaulting to the system--default python (2.x). How do I tell it to use python3.8?
Yes, I'm on a Mac. Python 3.8 is installed via Homebrew.
Answering questions from comments:
What does pip3.8 --version say?
3044 ~$ pip3.8 --version
pip 20.1.1 from /usr/local/lib/python3.8/site-packages/pip (python 3.8)
And check that which python3.8 points to /usr/local/lib/python3.8/python?
Not exactly. Is that bad?
3048 ~$ ll `which python3.8`
lrwxr-xr-x 1 grantb admin 40 Jul 24 10:57 /usr/local/bin/python3.8# -> ../Cellar/python#3.8/3.8.5/bin/python3.8
The issue is that if you look at the actual mssql-cli file it runs it using the python command. This (on my Mac) defaults to the 2.7 python. There are three solutions:
Add a line in your .bashrc or .bash_profile that says alias python='python3.8'. Note that this will override your python2.7 (which is obsolete anyway).
Edit the last line of the file that comes up with which mssql-cli to say python3.8 -m mssqlcli.main "$#". This has the disadvantage that you aren't really supposed to edit this, and that you'd need to do it every time you update this package, but it does work.
Run each mssql-cli command with the equivalent python3.8 -m mssqlcli.main.
Yet another brave soul caught up in the tangled web of installing Python on a Mac.
Your problem is that homebrew installed a version of Python in /usr/local/Cellar/python#3.8/3.8.5/bin/python3.8. Pip3.8, on the other hand, thinks Python is at /usr/local/lib/python3.8/python, so it installs its packages in that python's site-packages directory.
If you already had python with pip installed when you installed it from the Homebrew bottle, it won't overwrite the links you already had. One solution is to reinstall pip through the correct python.
python3.8 -m pip install -U --force-reinstall pip
This should force a reinstall of pip, and since python3.8 points to Homebrew's Python, it should install pip and pip3 as pointing to that python.

PIP and python installing packages

I have a CentOs system with both Python 2.7 and Python 3.4 installed. I do not have information regarding how these were installed.
However, this is the response when the following commands are issued:
whereis /usr/bin/python3
python3:
/usr/bin/python3.4
/usr/bin/python3.4m
/usr/lib/python3.4
/usr/lib64/python3.4
/usr/include/python3.4m
whereis /usr/bin/python2.7
python2:
/usr/bin/python2.7
/usr/bin/python2
/usr/lib/python2.7
/usr/lib64/python2.7
/usr/include/python2.7
/usr/share/man/man1/python2.1.gz
I am uncertain how to use PIP in this setup. Python documentation for PIP mentions it assumes that your environment is virtual.
If I want to install a module in python3.4 using PIP, what are the steps?
1. sudo as root?
2. set environmental variables?
3. etc...
Installing a Python package is fairly straightforward, you need to first verify that it's not already packaged by your distro, in your case:
yum search <module_name>
Those packages are generally named like: python-<module_name> for a Python 2 module and python3-<module_name> for a Python 3 module.
If it doesn't exist as a package, you can then rely on PyPI:
python3 -m pip install <module_name> --user
From my answer here
Let's break the this command in two parts:
python -m: Allows modules to be located using the Python module namespace for execution as scripts. The motivating examples were standard library modules such as pdb and profile. See PEP 338
--user : By default Python installs Python packages to system directories which requires root privileges, to avoid using sudo pip install (which is not recommended by the way) use this flag to make pip install packages in your home directory instead, which doesn't require any special privileges.
As a side note, if you have multiple versions of Python installed, keeping track of which Python version version pip is bound to can be a PITA, hence python -m, in this case you're sure that it's the pip bound to the Python called which will be executed.
While the previous method works (kinda), it's advised to use virtual environments because many Linux distributions (including CentOs) rely on some Python modules and you don't want to modify them unless you know what you are doing or you absolutely want to break your System.
Additionally, if you only want to "Install and Run Python Applications in Isolated Environments", you can check out pipx.
I always use pip3 when I want to directly refer to python3.
If I want to install a module in python3.4 using PIP, what are the steps? 1. sudo as root? 2. set environmental variables? 3. etc...
just this
sudo apt install python3-pip
pip3 install xyz

can't uninstall python3 in macOS

I am having trouble with my current python, so I wanted to uninstall my python and install the latest version. I installed with homebrew, so I uninstalled it with homebrew and reinstalled python 3.8.1 with the installer from the official site. Python3.8 was installed, but my python3 was not upgraded.
~ which python3
/usr/bin/python3
~ python3 --version
Python 3.7.3
I know I'm not supposed to(and I can't) manually delete things inside /usr/bin. What am I supposed to do?
When you installed Python with homebrew it told you this:
Unversioned symlinks python, python-config, pip etc. pointing to
python3, python3-config, pip3 etc., respectively, have been
installed into /usr/local/opt/python/libexec/bin
If you need a reminder, post install, you will get the same message if you run:
brew info python
It says "unversioned links are in /usr/local/opt/python/libexec/bin". That means, if you want to run Python without specifying the version, i.e. if you want to type this:
python
and this:
pip
to start Python 3 and its corresponding pip, you need to make sure your PATH has /usr/local/opt/python/libexec/bin at the start, i.e.
export PATH=/usr/local/opt/python/libexec/bin:$PATH
I could not uninstall the python3 in /usr/bin but found a workaround to give the python3 in /usr/loca/bin precedence by setting the PATH env variable as PATH=/usr/local/bin:$PATH. This gives binaries in /usr/local/bin precedence. Not a full fledged solution, but got me moving.

virtualenv couldn't find python interpreter path?

my computer have python3.4, python3.5, python3.6, python3.7, but now i want to use python virtualenv to create a env , but it show path not found?
The image in here:
You need to provide the full path to Python, for example:
virtualenv.exe -p C:\Python37\python.exe
For git-bash the command should be slightly different:
virtualenv.exe -p /c/Python37/python.exe
First of all having multiple versions of Python is not advised especially if you cant manage them. The issue you are getting stems from the installation of the Virtualenv package. You need to use the python version that has Virtualenv in the site-packages. Examine all the site packages for the 3 versions then use the one that has virtualenv alternatively you can uninstall all the 3 versions and reinstall one I'd advise on Python 3.6 then install virtualenv via pip and try again.

Status of Python 3.7 in Cygwin

Does anyone have a way to install python 3.7 in latest stable Cygwin 32 or 64 bit that works out of the box without hacking? I've noticed that 3.6 works fine but 3.7 libraries don't behave and are missing key functionality.
I have usecases to have Cygwin for various scripts but want to use 3.7 for its improvements with type annotations. The new Linux runtime is not available on my servers so Cygwin is the only decent posix environment I can run in my windows servers.
[Update - 2022-03-30] I recently have successfully gotten Python 3.9 working on Cygwin. It does create proper python3 and pip3 executables out of the box. Only issues need to install cryptography==3.3.2 and pyopenssl<=21.0.0 due to rust dependency.
Although Timothy's answer is correct, the cleaner way to do this is to ensure Cygwins 'alternative' package is installed and run the following commands in order to have your Python versions switchable through the alternative system. This will also switch to the correct pip versions.
/usr/sbin/update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 0 --slave /usr/bin/pip3 pip3 /usr/bin/pip3.6
/usr/sbin/update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 10 --slave /usr/bin/pip3 pip3 /usr/bin/pip3.7
/usr/sbin/update-alternatives --install /usr/bin/python python /usr/bin/python3 10 --slave /usr/bin/pip pip /usr/bin/pip3
/usr/sbin/update-alternatives --set python3 /usr/bin/python3.7
/usr/sbin/update-alternatives --set python /usr/bin/python3
In case you still need deprecated Python 2.x versions you can add these accordingly as an alternative for 'python' via a 'python2' group.
The python37 packages will install correctly but will create an executable called python3.7 instead of python3 which can be confusing. I would guess that the Cygwin dev's wanted to allow two versions of python3 to be installed at the same time.
However, as its not recommended to have two versions of python3 installed at the same time, you can simply create the executable python3 as follows to correct this:
ln -s /usr/bin/python3.7 /usr/bin/python3
The same goes for python37-pip:
ln -s /usr/bin/pip3.7 /usr/bin/pip3
These instructions above will likely apply to other non-standard version of python on Cygwin although I have only tested Python37.
For those who need to install pyopenssl package, you will need the following cygwin packages: gcc-g++, libffi-devel, libssl-devel, python37-devel
For pandas, you will need python37-numpy package and be sure to upgrade it in pip before installing pandas as there is a known bug in numpy package version in cygwin:
pip3 install --upgrade numpy
pip3 install pandas
python3 defaults to python 3.6 but python 3.7 is available in packages. Once installed you can run using:
$ python3.7 -V
Python 3.7.3

Resources