How can I change the Python interpreter in virtual environment (Ubuntu 18.04LTS)?

rbewoor :

I always used Anaconda on Windows so far and could set up an environment while choosing which exact Python to use. E.g. conda create -n myEnvName python=3.7

Now, I want to familiarize with Ubuntu 18.04 LTS and use basic Python environments.

So I followed these steps:

  1. Created folder in my home = ~/.venvPython
    • (a) I think I already had a 2.7 and 3.6 by default on the OS.
    • (b) I do not remember for sure, I think I had to do this sudo apt-get install python3-venv.
  2. Created environment this way after CD'ing to .venvPython folder ran this: python3 -m venv venv1BigDataPgm2
  3. source ~/.venvPython/venv1BigDataPgm2/bin/activate
  4. Command python --version says: Python 3.6.9

Running whereis Python shows this:

rohit@rohitUb18043LTS:~$ whereis python
python: /usr/bin/python3.6 /usr/bin/python3.6-config /usr/bin/python2.7-config /usr/bin/python3.6m-config /usr/bin/python /usr/bin/python3.6m /usr/bin/python2.7 /usr/lib/python3.8 /usr/lib/python3.7 /usr/lib/python3.6 /usr/lib/python2.7 /etc/python3.6 /etc/python /etc/python2.7 /usr/local/lib/python3.6 /usr/local/lib/python2.7 /usr/include/python3.6 /usr/include/python3.6m /usr/include/python2.7 /usr/share/python /usr/share/man/man1/python.1.gz

My doubts: Can I specify a Python version directly while creating the environment like with conda? How do I change this to some other interpreter instead of the 3.6.9? Do I have to manually install a different Python first, then point it somehow?

Please guide me. Thank you. Rohit

Redowan Delowar :

Usually, when I'm on Linux and don't need a specific python3 version, I create native python3 environments.

python3 -m venv myenv
source myenv/bin/activate

But if I need a specific python3 version, Miniconda environments are lightweight and works just fine.

conda create -n myenv python=3.6
conda activate myenv

To use a specific python3 version with native environments, you have to install that version using the indigenous package manager (eg. apt).

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=8608&siteId=1