How to setup the python environment
最后更新于
这有帮助吗?
最后更新于
这有帮助吗?
TIPS: In Windows parts of this instruction, use User as the username.
WARNING: In Linux parts of this instruction, only apply to any Debian-based distributions, e.g. Debain, Ubuntu, Linux Mint, elementary OS, etc.
If you are using the distribution that its package manager is not apt
, you need to convert all commands use apt
to the version of the package manager of the distribution that you are using, click here to see how to convert.
1. Go to PowerShell Github lastest release page and download msi installer for Windows, see the red box in the following image:
TIPS: The naming pattern of msi installer for Windows is PowerShell-<version>
-win-x64.msi. Select PowerShell-7.0.2-win-x64.msi if the lastest release version of PowerShell is 7.0.2.
2. Open the installer to install PowerShell, make sure every options in the installation are the same as the following image:
TIP: Default install location of PowerShell is C:\Program Files\PowerShell, you can change it if you want.
1. Go to Miniconda official site and click Miniconda3 Windows 64-bit to download the installer, see the red box in the following image:
2. Open the installer to install Miniconda, make sure every options in the installation are the same as the following image:
TIPS: Default install location of Miniconda is C:\Users\<username>
\miniconda3, you can change it if you want.
3. Open Start Menu, goto Anaconda3 (64-bit), open Anaconda Powershell Prompt (Miniconda3) and execute the following commands line by line:
4. Close Anaconda Powershell Prompt (Miniconda3), open PowerShell
WARNING: PowerShell here is referred to PowerShell (or pwsh.exe) that installed from step 0, not legacy Windows PowerShell (or powershell.exe) integrated in Windows. To open PowerShell, you can:
Open Start Menu, goto PowerShell and open PowerShell 7 (x64) if version 7 of PowerShell is installed.
Open Run dialog with keyboard shortcut ⊞ Win
+R
, input pwsh and press OK.
Use Windows Search, search pwsh and you can find it.
, and see the first line in the window must like:
If yes, Miniconda is successfully installed on Windows.
1. Go to Visual Studio Code official site and click Download for Windows to download the installer, see the red box in the following image:
2. Open the installer to install Visual Studio Code, make sure every options in the installation are the same as the following image:
TIPS: Default install location of Visual Studio Code is C:\Users\<username>
\AppData\Local\Programs\Microsoft VS Code, you can change it if you want.
1. Go to Git official site and click Download <version>
for Windows to download the installer, see the red box in the following image:
2. Open the installer to install Git, make sure every options in the installation are the same as the following image:
TIPS: Default install location of Git is C:\Program Files\Git, you can change it if you want.
1. Open PowerShell (Windows) or terminal (Linux).
2. Execute the following command to check the version of conda:
TIPS: If it is failed to execute, you need to reinstall Miniconda.
3. Execute the following commands line by line to configure and update conda:
config --set channel_priority strict
means set the channel priority to strict globally, click here for more details about channel priority.
update --all -y
means update all packages in current conda environment (now is base
) without confirm.
1. Open PowerShell (Windows) or terminal (Linux).
2. Execute the following command to check the version of Git:
TIPS: If your fullname is John Q. Public and email is john@example.com, you need to execute:
dev
for development in Visual Studio Code1. Open PowerShell (Windows) or terminal (Linux).
2. Execute the following command to create a conda environment:
create
means create a conda environment.
-n dev
means name of the environment is dev
.
--strict-channel-priority
means when creating new environment, all packages that installed will follow the strict channel priority.
-y
means without confirm.
python=3 jupyter pylint autopep8 rope
lists all packages will be installed when creating new environment, they are:
python=3
: Python 3.
jupyter
: Jupyter, include IPython and Jupyter Notebook, click here for more details.
pylint
: code analysis tool for Python, required in Visual Studio Code, click here for more details.
autopep8
: formatting tool for Python, required in Visual Studio Code, click here for more details.
rope
: refactoring tool for Python, required in Visual Studio Code, click here for more details.
3. Execute the following command to activate environment dev
:
This command will activate environment dev
over from base
.
4. Execute the following command to set the channel priority of environment dev
to strict:
This command will set the channel priority of current environment (now is dev
) to strict.
5. Execute the following command to deactivate current environment:
This command will deactivate environment dev
back to base
.
1. Open Visual Studio Code, you can open it from:
Start Menu (Windows) or Applications Overview (Linux).
Open Command Prompt, PowerShell (Windows) or terminal (Linux), and execute code
.
After you opened it, you must see the interface like the following image:
2. Follow the instructions of the following image to install Python extension:
3. Open settings of Visual Studio Code by:
Follow the instructions of the following image:
Use keyboard shortcut Ctrl
+ ,
.
4. Click Open Settings (JSON) button in the upper right corner of Visual Studio Code, see the red box in the following image:
5. Copy the following content into editor area:
TIPS: If you are using Linux, just ignore line 2 to 6, only:
WARNING: If you are using Windows, You need to replace <install location of PowerShell>
to the install location of PowerShell that you installed and escape \
to \\
.
For example, if your PowerShell is installed to default location C:\Program Files\PowerShell, you need to replace <install location of PowerShell>
to C:\\Program Files\\PowerShell
, like the following image:
6. Reopen Visual Studio Code.
1. Create a new file in Visual Studio Code by:
New file link in the Welcome page.
Select File → New File in menu bar.
Use keyboard shortcut Ctrl+N.
2. Write the following script into editor area:
This script means print Hello, World!
in terminal.
3. Save to a Python file (with file extension .py), like helloworld.py in the following image:
4. Click Run Python File in Terminal button in the upper right corner of Visual Studio Code, see the red box in the following image:
After clicked it, you must see the result like the following image:
You can see Hello, World!
in terminal area.