A Step-by-Step Guide to Creating Python Virtual Environments using Conda and PyCharm

A Step-by-Step Guide to Creating Python Virtual Environments using Conda and PyCharm

Python is currently the world’s most popular programming language, holding the number one rank as reported by PyPL Index. If you have started learning Python, you might have come across the term “Virtual Environments”. But what exactly are “Virtual environments”? In today’s article, I will provide a layman’s explanation of virtual environments. We will also create our own virtual environment in two Integrated Development Environments (IDEs): Anaconda and PyCharm. One of the benefits of creating virtual environments in Anaconda is that it allows you to use it in any other IDE, including Jupyter Notebook.

What is a Virtual Environment

If you are like me, you probably started working on a Python project by installing Python on your computer, installing required libraries using ‘pip’ in the terminal, and started writing Python script in a single file with the extension ‘.py’. Finally, you probably ran your program by executing it using the command ‘python file_name.py’.

This approach is fine for smaller projects as long as it gives you the desired output. But what if you started working on multiple projects with different requirements for various versions of the same packages and dependencies? This is not possible if you are using the global package. For example, if you are running Python 3.9 and the earlier version of NumPy and you start a new project that requires a newer version of NumPy, what is the solution?

The solution is to have two versions of NumPy: one for the older projects and another for the new project that needs a newer version of NumPy. This requires isolated libraries and other dependencies for each project, which is exactly what ‘Virtual Environments’ provides. Virtual environments ensure that you can manage your Python packages and avoid conflicts between different packages and their dependencies.

Creating Virtual Environments

You can create your own virtual environment using many modules such as virtualenv, venv, conda, pipenv, poetry, hatch, and pew. Due to its ease of use and ability to reproduce environments, conda is particularly popular among data analysts and engineers. One disadvantage of Anaconda distribution, which includes Conda, is that it can take up several gigabytes of disk space.

This article has been move to : https://medium.com/p/0139d000e7cd

References:

1.??? https://en.wikipedia.org/wiki/Anaconda_(Python_distribution)

2.??? Python IDEs and Code Editors (Guide), https://realpython.com/python-ides-code-editors-guide/

3.??? PYPL PopularitY of Programming Language, https://pypl.github.io/PYPL.html

4.??? https://docs.anaconda.com/distro-or-miniconda/

5.??? https://docs.anaconda.com/anaconda/install/windows/

6.??? https://www.geeksforgeeks.org/python-virtual-environment/

7.??? https://docs.python.org/3/tutorial/venv.html

8.??? https://www.tensorflow.org/versions

9.??? https://www.arch.jhu.edu/python-virtual-environments/

10. https://docs.anaconda.com/working-with-conda/ide-tutorials/pycharm/

要查看或添加评论,请登录

社区洞察

其他会员也浏览了