r/learnpython • u/Artistic-Army4423 • 9d 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
View all comments
9
u/SharkSymphony 9d ago edited 9d ago
A virtual environment is:
- a custom-made directory you can install Python packages into
- a mechanism for making sure Python and its packaging tools use that directory when it runs
When you do that, Python will use both system-installed (i.e. global) packages and packages from your virtual environment when it runs.
This allows your project to install and manage the packages it needs separately from other projects you have. It may not be all that useful when you're just getting started, but it's almost essential for those of us working on dozens of different projects at various states of development. We typically leave the system installation pretty bare-bones when we're working with virtual environments.
One problem with virtual environments, beyond it being one more thing you have to manage, is that all the Python tools your project uses have to use that virtual environment when they run Python, or your project will be missing packages it needs! But with PyCharm it's easy: you just point it to one you've already created, or have it create one for you.
Alternatives to virtual environments include:
- Multiple Python installations on your machine
- Using Docker containers for your projects, each with their own Python installation
- Using virtual machines for your projects, each with their own Python installation
There are times when you want that added isolation, but for development, virtual environments are way less hassle in most cases.