Can installing two python versions can cause problems? - python

I've install 3.7.9 and 3.9.7 and installed some packages (including pandas and numpy) but after doing so running or using them in programs some of them are executable in first or second versions of the python how to overcome this ?
Should I just delete any one of the version or there is any remedy for this

You can install multiple python versions without a problem. Whenever you install a package though, it will only be installed into one of the two python versions. You therefore need to install once for python 3.7.9, and once for python 3.9.7. Depending on which OS you are running, you can run the different versions through python3.9 or python3.7. Lets say you want to install pandas on python3.9, you run python3.9 -m pip install pandas.
In general, it is a good idea to use virtual environments (see venv for example). This will install all the dependencies that you have for a project separately. In the long run, such approach will avoid problems with compatibility after upgrading to newer python versions or package versions.

Related

Modules installed but not found by Python in Raspberry Pi 3

I have a Raspberry Pi 3 with Raspbian and I upgraded python version from 3.7 to 3.8. If I type python --version in the terminal the correct version appears as the system version. However none of the modules that I have installed AFTER the version change seem to work. Python gives ModuleNotFoundError when trying to import ANY of the modules that I have installed.
I can see the modules with pip freeze but Python seems to not be able to find them.
I followed this instructions to purge 3.7. I reinstalled pip after purging python 3.7 but pip as again installed in /home/pi/.local/lib/python3.7/site-packages/pip. How can I get rid of 3.7 completely?
python3.8 -m pip install SomePackage # specifically Python 3.8 should work.
More documentation here: https://docs.python.org/3/installing/index.html#work-with-multiple-versions-of-python-installed-in-parallel
Just to summarize the comments and suggestions from other answers:
The problem I have was caused by the fact that even I had set Python 3.8 as default and python -v was pointing to Python 3.8 the pip script was installing modules for Python 3.7.
The suggested solution was to use pip3.8 (or whatever version someone might have) to install packages for that equivalent Python version and that works good.
Ideally best option if someone wants to have multiple versions of python is to use pyenv. You can create multiple virtual environments with multiple python versions.
However Do not uninstall the default Python. I have also tried to uninstall the default Python 3.7 to avoid having two versions of python 3 and keeping track of which module is installed where. This was a bad idea. I did not know that many Linux distributions have applications which use the default Python. You might get a black screen and who knows what other problems see this discussion Removed Python 3 on 18.04, how can I fix my system?

distutils and pygame for python 3.7 on a machine running python 3.8

I'm quite new to Ubuntu. On my machine, running Ubuntu 20.04 with Python 3.8, I'm trying to run a program which does not support Python 3.8, but it requires Python 3.7 (FYI, it is Carla Simulator).
I need pygame, but when installing it through pip (python3.7 -m pip install pygame) it raises an error:
ModuleNotFoundError: No module named 'distutils.util'
Now, I have distutils correctly installed and updated at version 3.8.2-1ubuntu1.
Is there any way for me to install a distutils version compatible with Python 3.7 without affecting Python 3.8 and related modules? Or do you have hany suggestion to get pygame for Python 3.7 and running Carla somehow? Could a virtual environment help?
My question is really similar to this one How to install python-distutils but I don't actually require distutils, I just need the program to work...
Thank you
----- EDIT -----
I tried creating a virtual environment using venv, but I got an error due tue unavailability of ensurepip. Googling it, I found it might be related to the fact that my Python 3.7 version might have been installed through Anaconda (I actually can't remember). Running apt-cache rdepends python3.7 I get:
python3.7
Reverse Depends:
python3.7-minimal
Is it safe to completely uninstall current Python3.7 and reinstall it to hopefully get ensurepip? Any suggested code to safely do it?
The easiest solution for you would be to run your program in a virtual environment where you would specify the default python version to be 3.7 I think (see Use different Python version with virtualenv for an example). You can then install all your dependencies inside this environment and not have to deal with any conflicts between the two versions on Python.
Using pyenv you could specify the python version you want to use.
for example:
create a new folder and hit:
pyenv local 3.7.2
then create your virtual env by using pipenv:
pipenv install
then start your journey to building your game.
hope it help.

Error when installing Tensorflow - Python 3.8

I'm new to programming and following a course where I must install Tensorflow. The issue is that I'm using Python 3.8 which I understand isn't supported by Tensorflow.
I've downloaded Python 3.6 but I don't know how to switch this as my default version of python.
Would it be best to set up a venv using python 3.6 for my program and install Tensorflow in this venv?
Also, I using Windows and Powershell.
Tensorflow is only supported until python 3.7 as of now.
You can check it here: https://www.tensorflow.org/install/pip
But there is a way to install it on Python3.8, just run the below command that will do your job:
python -m pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.12.0-py3-none-any.whl
This command work on mac and windows both, I haven't tested on Linux.
You should always use venv because by default every project on your system will use these same directories to store and retrieve site packages (third party libraries). At first glance, this may not seem like a big deal, and it isn’t really, for system packages (packages that are part of the standard Python library), but it does matter for site packages.
Consider the following scenario where you have two projects: ProjectA and ProjectB, both of which have a dependency on the same library, ProjectC. The problem becomes apparent when we start requiring different versions of ProjectC. Maybe ProjectA needs v1.0.0, while ProjectB requires the newer v2.0.0.
You can also take a look at anaconda, it’s the most populasr data sciencie platform and will be easy for you install tensorflow and jupiter notebook in just 2 clicks. Anaconda
Uninstall all your python versions and use the latest anaconda.
$ conda create --name tensorflow python=3.5
This way you create a virtual environment with python 3.5 which is supported by tensorflow.
So now you can install it.
$ activate tensorflow
(tensorflow) $ pip install tensorflow
it would have been nice if you would have the share the error screenshot
though as per i got the case
tensorflow work in both 3.8 and 3.6 just you have to check that you have 64bit version not 32 bit
you can acess both version from thier respective folder no need to install a venv
If you don't want to use Anaconda or virtualenv, then actually multiple Python versions can live side by side. I use Python38 as my default and Python35 for TensorFlow until they release it for Python38. If you wish to use the "non-default" Python, just invoke with the full path of the python.exe (or create a shortcut/batch file for it). Python then will take care of using the correct Python libs for that version.
Worked on Python 3.8.2 (default, Mar 05 2020, 18:58:42) [GCC] on linux
pip3 install --upgrade tf-nightly
Python Versions 3.5 - 3.8 are supported now.
You can verify on this page:
https://www.tensorflow.org/install/pip

Is there any benefit of using Anaconda for PyCharm?

Is there any benefit of using Anaconda for PyCharm instead of the standard python distribution for PyCharm?
Using Anaconda instead of standard Python will benefit you as Anaconda comes with preinstalled packages. A lot of time will be saved there since installing various packages and making them run gets irritating sometimes.
Also, since it will have preinstalled packages, it can be heavy for your system. You can try miniconda as an alternative where you install packages when required. It is still better than having Python only. You can even install Anaconda by using conda install anaconda
Pip installation of Python packages sometimes may cause few problems to the user and you need to constantly update the pip as well before installing any other python packages via pip. So using Anaconda will be a benefit in this case.

how to use pip install a package if there are two same version of python on windows

I have two same versions of python on windows. Both are 3.6.4. I installed one of them, and the other one comes with Anaconda.
My question is how do I use pip to install a package for one of them? It looks like the common method will not work since the two python versions are the same.
pip points to only one installation because pip is a script from one python.
If you have one Python in your PATH, then it's that python and that pip that will be used.
Use virtualenv, conda environment or pipenv, it will help with managing packages for different projects.

Categories

Resources