使⽤python虚拟环境配置pycharm
It will show you how to configure PyCharm to work with Python in a virtual environment. Also you will configure
它将向您展⽰如何配置PyCharm以在虚拟环境中使⽤Python。 另外,您将配置。
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的安装版本。
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”:
If all went well you will have the folder venv in your project:
如果⼀切顺利,您的项⽬中将拥有venv⽂件夹:
To activate virtual environment lunch:
激活虚拟环境午餐:
Python解释器 (Python Interpreter)
If you can’t find the python interpreter in the previous window then you have to create or add it. Just go to File →Settings →Project →Python interpreter →Add.
如果在上⼀个窗⼝中不到python解释器,则必须创建或添加它。 只需转到⽂件→设置→项⽬→Python解释器→添加。
In the Interpreter box is present the path of our virtual environment:
在“解释器”框中,提供了我们虚拟环境的路径:任务句柄是什么
Click Ok and then on Apply, then we will see all the libraries installed in our virtual environment.单击确定,然后单击应⽤,然后我们将看到虚拟环境中安装的所有库。
在虚拟环境中执⾏程序 (Executing a program in the virtual environment) Let’s consider the example fi
rst_example, go to Add Configuration…
让我们考虑⽰例first_example,转到Add Configuration…。
matlab median函数A window will open. Click on the “+” in the upper left corner. Now we can configure our Python program ready to run. Enter the “Name” (first_example), set “Script path” to the file where the main is located. Then we should find the “Python interpreter” already configured, in any case, having added it we will find it in the dropdown menu. Note that the interpreter path is the one related to the virtual environment created!
将会打开⼀个窗⼝。 单击左上⾓的“ +”。 现在,我们可以配置我们的Python程序以准备运⾏。 输⼊“名称”(first_example),将“脚本路径”设置为主⽂件所在的⽂件。 然后,我们应该到已经配置的“ Python解释器”,⽆论如何添加它,我们都会在下拉菜单中到它。 请注意,解释器路径是与创建的虚拟环境相关的路径!
午餐简单程序 (Lunch simple program)
Let’s consider the following code:
让我们考虑以下代码:
import pandas as pd
if __name__ == '__main__':powderroom是什么意思
print("First Example")
data = {'First Column Name': ['First value', 'Second value'],
'Second Column Name': ['First value', 'Second value']}
df = pd.DataFrame(data, columns=['First Column Name','Second Column Name'])
print(df)
汇编语言第4版pdfpycharm python安装教程the result:
结果:
初学编程看什么书< ()
If you share a project with other users using a build system or plan to copy the project to another location where an environment is to be restored, you must specify the external packages required by the project. The recommended approach is to use file, which contains a list of pip commands and allows you to install the required versions of dependent packages.
如果您使⽤构建系统与其他⽤户共享项⽬,或计划将该项⽬复制到要还原环境的另⼀个位置,则必须指定该项⽬所需的外部软件包。 推荐的⽅法是使⽤⽂件,该⽂件包含pip命令的列表,并允许您安装所需版本的从属软件包。
We assume to install Pandas (data analysis and manipulation tool), we lunch:
我们假设安装Pandas(数据分析和操纵⼯具),我们午餐:
pip3 install pandas
In this case version 1.1.2 of pandas has been installed since we have not expressed a preference on the version. Because we will develop several things with this version, some methods may become deprecated, so to save the installed version, we create file in the root directory of the project.
在这种情况下,已经安装了熊猫的1.1.2版本,因为我们没有对此版本表⽰偏好。 因为我们将使⽤该版本开发⼀些东西,所以某些⽅法可能会被弃⽤,因此要保存安装的版本,我们在项⽬的根⽬录中创建了⽂件。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论