r/learnpython • • 10d ago

Virtual Environment and Python

I have started learning python and decided to use pycharm as an editor. I want to know anything which will help me in this journey.

My main question is => I don't get "virtual environment" thing with python. I cloned a repo and opened it in pycharm, it says "No python interpreter configured for <repo-name>" and then suggested to create virtual environment.

I want to hear things from experience devs.

thank you.

4 Upvotes

43 comments sorted by

View all comments

1

u/Confident_Hyena2506 10d ago

If you don't have any python then you can't run any python.

And you will need lots of different versions of python for different projects - virtual env is just a way to organise them.

2

u/Artistic-Army4423 10d ago

alright, I feel it's kind of similar to node_modules in JS repos. Also, so there are other things as well which can do similar things, I will check them out

1

u/SharkSymphony 10d ago edited 9d ago

Yes, that's exactly what it is... but because it was added to the Python ecosystem as a third-party tool, you have to do a little more work (that `source venv/bin/activate` thing) to have Python and its tools use it.

(I guess if I'm being super-technical I'd clarify there's one difference between them – the ability for Javascript to work with different versions of the same library in the same node_modules, pulled in via different dependencies. With Python virtual environments, you're generally stuck with one version at a time.)

1

u/Discordbothost 9d ago

node_modules is a pretty good mental model. the main differences: a venv also pins which python interpreter runs, not just the packages, and python doesn't pick it up automatically from the folder like node does, you either activate it or point your editor at .venv. requirements.txt (or pyproject.toml) is the package.json part. if you want the npm-ish feel, uv does it: uv init, uv add requests, uv run main.py and it handles the venv for you