[Python Basics] Using Python and installing Python packages in VS2019
Article directory
Preface
If you want to use Python language to write some programs, which IDE to use is a question. If you are professionally developing Python, PyCharm is undoubtedly the best choice. As a programmer who uses VS more, writing Python directly in VS is a good choice. This article mainly introduces the process of installing the Python environment in VS2019, configuring the environment after installation, and using pip install *** to install the Python package.
1. Install the Python environment in VS2019
Choose to install python when installing VS2019
If you did not choose to install python when installing VS2019, you can search for and install Python development in the extension
Then open VS2019, create a new project, and select python application
2. Python environment variable configuration
If you directly pip install the package name of the newly installed Python and the package installation fails, it may be because the environment variables are not configured.
Click to open in PowerShell as shown in the figure to view the location of Python installation.
You can see the installation location here:
Copy this address and search for this location directly on your computer:
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64
Find the system environment variable path and add two new environment variables:
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\Scripts
3. Install Python package
After configuring the environment variables, go back to VS2019 to create a new python project, click Solution Explorer, and right-click to manage python packages in Python 3.7 in the Python environment:
Enter the name of the package to be installed, and click to run the command pip install pandas. If the permissions are required, upgrade immediately and grant administrative permissions.
Then the left display output setting is: General, observe the installation situation. The installation may be time-consuming, and it may still show that the installation was not successful for a long time. You can reopen VS2019 after a while to refresh and view. After the installation is completed, the installation success will be displayed. You can see the pandas package where you search for packages.
Enter a piece of test code and run:
import pandas as pd
# 创建一个字典
data = {
'姓名': ['张三', '李四', '王五'],
'年龄': [25, 30, 35],
'性别': ['男', '女', '男']}
# 将字典转换为DataFrame
df = pd.DataFrame(data)
# 打印DataFrame
print(df)
Summarize
Install pyhton environment
Configure pyhton environment
Install pyhton package