Windows 10 batch command line setting environment variable notes without reinstalling python and chrome

Recently, I often install and deploy python production and development environments at work, which is quite troublesome and I am not in the mood to optimize. Suddenly, my computer crashed. During the process of reinstalling the computer, I kept the original installation software (some were not placed in the system disk) and directly used the early installation software by modifying the environment configuration variables. It was very useful.

First, organize the environment variable settings and write a batch script. Secondly, back up python (including a large number of third-party tool packages numpy, pandas, jupyter, etc.) and chrome installation folders. The key points are as follows:

1. Batch command line setting environment variable script

Under the cmd command line, the set command can set temporary environment variables, and its scope of action is: only valid in the current window; setx directly writes to the registry and is globally valid (need to restart the command line window). Run the set command without parameters to query all environment variables of the current system, and run the path command to query the path variables.

grammar:

  • set name can view the environment variable
    set name=value
  • setx can permanently set local environment variables
  • setx /m permanently sets system environment variables
    setx /m name “value”
  • setx -m permanently appends system environment variables
    setx -m name “%name%;value”

You can set environment variables using the following command:

setx -m JAVA_HOME "D:\Program Files\jdk-11"
setx -m path "%path%;%JAVA_HOME%\bin"
setx -m path "%path%;C:\Python\Python38\;C:\Python\Python38\Scripts\;C:\Program Files\Google\Chrome\Application"
mkdir C:\Users\%USERNAME%\.jupyter
mkdir D:\jupyterworkspace
copy jupyter_notebook_config.py C:\Users\%USERNAME%\.jupyter\jupyter_notebook_config.py

Note: setx -m path “%path%;C:\Python\Python38;C:\Python\Python38\Scripts;C:\Program Files\Google\Chrome\Application”, change to: setx -m path “C: \Python\Python38;C:\Python\Python38\Scripts;C:\Program Files\Google\Chrome\Application;%path%", the python environment variable is advanced. The detailed reasons will be seen later.

Among them, %USERNAME% is the current system user.

Write the above code into the setxENV.bat file and run it as a system administrator.

2. Completely solve the problem of pop-up windows app store when running python under windows10 cmd

Method 1: Move down the environment variables of the Microsoft Store

First, you can move C:\Users\xiao\AppData\Local\Microsoft\WindowsApps in the environment variables to the python environment variables, as shown in the figure below.
Insert image description here

Just like this, click on the Microsoft environment variables, then click Move down and move it to the back of the python path.

As above, the environment variable setting script becomes: setx -m path "C:\Python\Python38;C:\Python\Python38\Scripts;C:\Program Files\Google\Chrome\Application;%path%", python row This phenomenon can also be solved in the first place.

Method 2: Delete the environment variables of the Microsoft App Store

3. Unzip the original installation content

For the chrome browser, it is usually installed in C:\Program Files\Google (versions starting from 2023). The effect of moving or copying is as follows.
Insert image description here
The environment variable configuration is as set above "C:\Program Files\Google\Chrome\Application". Among them, "chromedriver.exe" is related to this article " Introduction to Crawler Practice Based on Selenium Technology Solution ".

For Python and its Jupyter development environment, configure the settings as above.

Python decompresses the deployment directory and places it on the C drive (no need to reinstall, as well as its toolkit), as shown in the following figure:
Insert image description here

Its Jupyter development environment custom configuration file directory is as shown in the figure below.
Insert image description here
The above content can also be executed using command line scripts. There are two methods:

Method 1: Command line tar command.

mkdir D:\PythonData
tar -xzvf Python.zip -C D:\PythonData
tar -xzvf Google.zip -C D:\PythonData
setx -m JAVA_HOME "D:\Program Files\jdk-11"
setx -m path "%path%;%JAVA_HOME%\bin"
setx -m path "%path%;D:\PythonData\Python\Python38\;D:\PythonData:\Python\Python38\Scripts\;D:\PythonData\Google\Chrome\Application"
mkdir D:\PythonData\App
copy *.py D:\PythonData\App\
copy *.bat D:\PythonData\App\
copy *.lnk D:\PythonData\App\
copy 小区列表查询.lnk C:\Users\%USERNAME%\Desktop\
copy 小区信息查询.lnk C:\Users\%USERNAME%\Desktop\

Method 2: Powershell command.

powershell Expand-Archive -Path Python.zip -DestinationPath D:\PythonData
powershell Expand-Archive -Path Google.zip -DestinationPath D:\PythonData
setx -m JAVA_HOME "D:\Program Files\jdk-11"
setx -m path "%path%;%JAVA_HOME%\bin"
setx -m path "%path%;D:\PythonData\Python\Python38\;D:\PythonData:\Python\Python38\Scripts\;D:\PythonData\Google\Chrome\Application"
mkdir D:\PythonData\App
copy *.py D:\PythonData\App\
copy *.bat D:\PythonData\App\
copy *.lnk D:\PythonData\App\
copy 小区列表查询.lnk C:\Users\%USERNAME%\Desktop\
copy 小区信息查询.lnk C:\Users\%USERNAME%\Desktop\

Note: The powershell Expand-Archive command can create directories, but tai can only be decompressed into the specified directory. Of course, both can be decompressed directly, including the internal directory structure.

reference:

Xiaoji0622. Windows uses the CMD command line to set environment variables . CSDN Blog. 2023.07

Guess you like

Origin blog.csdn.net/xiaoyw/article/details/132447766