It will show you how to configure PyCharm to work with Python in a virtual environment. Also you will configure the requirements.txt.
它将向您展示如何配置PyCharm以在虚拟环境中使用Python。 另外,您将配置requirements.txt。
Start PyCharm create a new project or clone it from your repository. As an example I created a file first_example.py to write inside the main. I specify that this is only an example and for reasons of brevity does not follow the structure of a Python project.
启动PyCharm创建一个新项目或从您的存储库中克隆它。 作为示例,我创建了一个文件first_example.py写入main内部。 我指定这只是一个示例,为了简洁起见,它不遵循Python项目的结构。
安装Python (Install Python)
First, make sure Python 3 is installed by running the following command:
首先,通过运行以下命令确保安装了Python 3:
python --version
python3 --version
If python 2 and 3 is installed, the output will be the installed version of python 2 and 3.
如果安装了python 2和3,则输出将是python 2和3的安装版本。
![Image for post](https://i-blog.csdnimg.cn/blog_migrate/18bda9b58f81af12fcbabcaaba7486e7.png)
If python is not installed, run the command and choose version 3.6 for example¹:
如果未安装python,请运行命令并选择版本3.6,例如¹:
sudo apt-get install python3.6
sudo apt install python3-pip python3-venv
Create virtualenv with:
使用以下命令创建virtualenv:
python3 -m venv <venv-directory>
It is possible to create virtualenv on the same directory or on a different directory. In this article I use the same directory as the project directory. In my case i call the directory “venv”, but we can use “any_name”:
可以在同一目录或不同目录上创建virtualenv。 在本文中,我使用与项目目录相同的目录。 就我而言,我将目录称为“ venv”,但我们可以使用“ any_name”: