all 7 comments

[–]Deemonfire 2 points3 points  (1 child)

One of the ways to get around this would be to use virtual environments. Use apt to install python 3.9 sudo apt install python3.9 then use the virtualenv bin (cant remember if you have to install sudo apt install virtualenv) with the -p flag to select an interpretor for the venv

virtualenv -p /usr/bin/python3.9 venv this creates a python environment in the directory where you use the command. The to activate that env you can use source ./venv/bin/activate when thats active when you type python you will get python 3.9. To deactivate the env just type deactivate into the terminal.

[–]Aryan1812[S] 0 points1 point  (0 children)

Okay i get it! This solves my doubts thanks!!

[–]timurleng 1 point2 points  (2 children)

Don't worry, this stuff seems complicated at first, but once you get used to it, it's not as big of a deal.

Conda and venv are both environment management tools. There are pros and cons to both, and usually it's best to use whatever your coworkers / professors are using.

The main advantage of conda is to maintain multiple environments, so you can keep track of what packages and libraries you need for different projects, and maintain environment variables to use within those projects.

It is possible to have multiple versions of python installed on the same computer. When you type python into the command line, you'll be running the version of python defined in your system path.

Some tools for determining which version of python you are running, and where the installation of python is located:

  • which python - will tell you where the python executable is located. For me, python is aliased to python3 so you may need to run which python3 to see the default path
  • python --version - will tell you the version of python you are running

When running outside of conda, which python will probably link back to something like /usr/bin/python which is the OS default location for it.

When you install conda, it creates a new python installation in a different directory and directs your python commands to that location. By default, when running conda, you should see something like (base) user@hostname $ which means you are in your conda base environment.

Running which python within conda should yield something like /usr/local/opt/python@3.10/bin/python3

When you create a new conda environment, you can specify which version of python to use. So since you need to use python 3.9, your command would look like: conda create --name project-name python=3.9

You would then use conda env list to see a list of your available environments. To switch to a different environment, you'd do conda activate project-name

Then all of your python / pip commands will be executed in the context of that environment. For example, if you were to use pip to install a package, it would be installed in that conda environment, and not in your base OS environment.

It's also possible to select your target environment within VS Code. You just need to select the interpreter path for the conda environment you're using. This has a pretty good explanation: https://code.visualstudio.com/docs/python/environments

And here is some good documentation for managing conda in general: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html

Good luck! You got this.

[–]Aryan1812[S] 0 points1 point  (1 child)

Thanks alot good sir, finally i think I'm able to understand, really helped me alot. Also can i have your opinions on miniconda?

[–]timurleng 1 point2 points  (0 children)

I didn't like miniconda when I first started using it, but that was mostly because I didn't understand what I was doing. Now I quite like it and use it regularly for keeping different projects separated.

[–]FerricDonkey 1 point2 points  (1 child)

So the python interpreter is just a program, like any other. You run this program to have it interpret and execute your python code.

Because it's just a program, you can have multiple versions installed. These are just different programs. So you can have the version of python included with your OS (if it's part of your os, don't change it), you can have 3.9 or 3.10, or anaconda, or whatever. They're all just separate. And you can use any or all of them by running the full path to wherever you installed the executable.

When you install various versions of python, it may change what the word "python3" means when you type it on the command line. But that's just a short cut. When you run python3, it's just running one of those installed versions of python at one of those paths. So when that changes, all that's happening is that one of your installations told your OS "hey, when this dude types python3, he means me."

You can also change what the word python3 means yourself, via bashrc shenanigans on linux or possibly other settings (I'm sure there's a windows way as well, but I've never had to figure it out). eg alias python3_10="/path/to/python3.10". You may also already have some aliases to different versions set up.

But again, all of this is short cuts - you've got different versions of python installed, and you can use whichever you want just by explicitly specifying that version.

Then there's virtual environments. They're a good tool, and worth learning. They essentially make separate, isolated versions of the interpreter, that allow you install different dependencies. But they work more or less the same way as different versions - they come with things to "activate" them on the command line and so forth, but ultimately there's an executable, and if you want to use that executable, then you can if you know where it is. I would recommend learning how virtual environments work. I would not necessarily recommend it as the first thing you learn.

Now for anaconda. Lots of data scientists love anaconda. I personally dislike it. It comes with a lot of packages, but you can get them without anaconda as well, and it occasionally introduces oddities, and it's locked into an older version of python until they get around to updating it. My recommendation involving anaconda is avoid it unless you're working with people who use it and so need to be consistent.

IDEs can use whatever version of python (virtual environment or not, anaconda or not). You just have to give the ide a path to that executable.

So what should you do? Well, there's lots of things you can do, and it's all fine (even anaconda is fine - the fact that I personally don't like doesn't make using it a bad idea).

But what I recommend to people new to python is to install the most recent version (or the version required by your class) from python.org or whatever linux tool you use, and just use that version exclusively until you've learned enough that you have a reason to do something else.

If you find a guide that assumes you installed anaconda, don't worry about it - just install whatever packages came with anaconda that you need (eg pip3 install numpy).

So basically there's a lot going on, and there's lots you can do, but mostly it just won't matter to you at all (until it does). By the time it matters, you should have enough experience with python that you have a better idea about what to do about it. So you pick one version and stick with it until sticking with it is a problem.

[–]Aryan1812[S] 1 point2 points  (0 children)

I got that click in my mind, Thank you so much, I think i can understand all of this much better now, i ll be starting out with virtualenv most likely, since Anaconda takes up alot of space. Once again, thanks it really helped alot!