How to run Python on Windows without polluting the environment as much as possible (Scoop edition)

[Introduction]

For some reason, the number of views is steadily increasing "How to run Python on Windows without polluting the environment as much as possible" series [^ 1]. It seems that there is unexpected demand, so I will describe my recent favorite method. Unlike the Embeddable version introduced in the past, this procedure is characterized by the fact that tkinter and venv can be used, and unlike the WSL version, it is not subject to HW restrictions. Also, the procedure is only 2 steps, which is very easy.

[Details]

Using the package management tool "Scoop" for Windows, install Python without polluting the Windows environment as much as possible so that you can develop and check the operation. ** (* The user environment variable PATH will be added / changed, so if you are interested in it, please withdraw here) **

【procedure】

1. Install Scoop

First, install the package management tool "Scoop". Scoop itself is a very lightweight tool, and the modules installed by Scoop are installed in the user folder by default, so they do little to pollute the Windows system environment.

Please refer to the following article for a simple installation method of Scoop. [Environment construction using Scoop]-Qiita

If you want to use it for the time being, execute the following command from PowerShell to install Scoop. When you see the policy change message, enter "Y" to proceed.

Set-ExecutionPolicy RemoteSigned -scope CurrentUser
invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')

2. Python installation

After installing Scoop, install Python. Execute the following command from PowerShell or the command prompt.

scoop install python

** Python installation is complete. ** **

To run Python, start it with python or python3 from a command prompt. Then install the required modules with pip install or create a virtual environment with python -m venv.

The Python installed in this procedure calls the command in % userprofile% \ scoop \ shims at startup, but the entity is located in% userprofile% \ scoop \ apps \ python.

[Supplement --About Python version 1]

The latest version is basically installed for installation by Scoop. For example, if you execute scoop install python, Python 3.8.5 will be installed at the time of this article (2020/09/02). If you want to install another version, you'll need to do a little extra work.

If you need an older version of Python 2.7, 3.5, 3.6, 3.7, please do the following:

scoop install git         #Install Git as you will need it for the following tasks
scoop bucket add versions #Add versions bucket
scoop install python37    # python3.Install the "latest version" of 7

You can check the installable version with scoop search python after executing scoop bucket add versions with the above command.

#Search for packages
scoop search python
#=>'main' bucket:
#=>    aws (1.18.44) --> includes 'python.exe'
#=>    python (3.8.5)
#=>    winpython (3.8.5.0)
#=>
#=>'versions' bucket:
#=>    anaconda2 (2019.10) --> includes 'python.exe'
#=>    miniconda2 (4.7.12.1) --> includes 'python.exe'
#=>    python-alpha (3.9.0b5)
#=>    python-beta (3.8.4rc1)
#=>    python27-beta (2.7.18rc1)
#=>    python27 (2.7.18)
#=>    python35 (3.5.4)
#=>    python36 (3.6.8)
#=>    python37 (3.7.9)

In addition, only the latest version of each version can be installed by this procedure. There is also a way to specify a fine revision, but I will omit it here.

As mentioned above, the command installed by Scoop calls the command % userprofile% \ scoop \ shims, but when multiple versions are installed, this is the last one installed. It may be overwritten by and run with an unintended version. Basically, it is possible to execute with the intended version with the command according to the version. (Python or python37 in the above example) However, common commands such as python3 and ʻidel / idle3will be executed with the last installed version. To fix this, you can use thescoop reset command to fix the commands in% userprofile% \ scoop \ shims`. In the case of the above example, it will be as follows.

#Check the current version(Final installation is 3.7.9)
python3 -V
#=>Python 3.7.9

# 3.7.Switch from 9 to the latest version
scoop reset python
#=>Resetting python (3.8.5).
#=>Linking ~\scoop\apps\python\current => ~\scoop\apps\python\3.8.5
#=>Creating shim for 'python'.
#=>WARN  Overwriting shim to python.exe installed from python37
#=>Creating shim for 'pythonw'.
#=>WARN  Overwriting shim to pythonw.exe installed from python37
#=>Creating shim for 'python3'.
#=>WARN  Overwriting shim to python.exe installed from python37
#=>Creating shim for 'idle'.
#=>WARN  Overwriting shim to idle.bat installed from python37
#=>Creating shim for 'idle3'.
#=>WARN  Overwriting shim to idle.bat installed from python37

#Confirmation of version change(3.7.9 to 3.8.Has changed to 5)
python3 -V
#=>Python 3.8.5

#3 from the latest version.Change to 7 series
scoop reset python37
#=> (Output omitted)

#Confirmation of version change(3.8.5 to 3.7.Has changed to 9)
python3 -V
#=>Python 3.7.9

[Supplement --About Python version 2]

I don't have version control the above way. Directly hit the actual file of the desired version of Python located in % userprofile% \ scoop \ apps \, and create and manage a virtual environment for each development environment with venv.

#Virtual environment creation example(PowerShell)
#When executing at the command prompt, "~"" Part%userprofile%To
#   「activate."ps1" to "activate".Please change to "bat"

#Create folder for virtual environment(Please change to a suitable folder if necessary)
mkdir c:\venv

##################################################
# Python3.8.Creating a virtual environment for 5(=>c:\venv\python38)
##################################################
~\scoop\apps\python\3.8.5\python -m venv c:\venv\python38

C:\venv\python38\Scripts\activate.ps1    #Activate virtual environment
python -V                                #Version confirmation
#=>Python 3.8.5

pip install numpy                        #numpy "latest" version installation
pip install pandas                       #Install the "latest" version of pandas

pip freeze                               #Check installed modules
#=>numpy==1.19.1
#=>pandas==1.1.1
#=>(Omitted below)

deactivate                               #Get out of the virtual environment


##################################################
# Python3.7.Creating a virtual environment for 9(=>c:\venv\python37)
##################################################
~\scoop\apps\python37\3.7.9\python -m venv c:\venv\python37

C:\venv\python37\Scripts\activate.ps1    #Activate virtual environment
python -V                                #Version confirmation
#=>Python 3.7.9

pip install numpy==1.15                  # numpy 1.15 installations
pip install pandas==1.0                  # pandas 1.0 installation

pip freeze                               #Check installed modules
#=>numpy==1.15.0
#=>pandas==1.0.0
#=>(Omitted below)

deactivate                               #Get out of the virtual environment


##################################################
#Confirmation of real environment
##################################################
python -V
#=>Python 3.8.5

pip freeze
#=> (No return value)

[^ 1]: [How to run Python on Windows without polluting the environment as much as possible (Windows 10, version 1607 or later using WSL only)]
[How to run Python on Windows without polluting the environment as much as possible (Python embeddable version)]

Recommended Posts

How to run Python on Windows without polluting the environment as much as possible (Scoop edition)
How to run GUI programs such as tkinter in Python environment on WSL2
Run the program without building a Python environment! !! (How to get started with Google Colaboratory)
How to manage Python minor version (build virtual environment) on Windows (without Pyenv or WSL)
[Kivy] How to install Kivy on Windows [Python]
Dedicated to beginners! How to learn programming without spending as much money as possible
Put MicroPython on Windows to run ESP32 on Python
How to run MeCab on Ubuntu 18.04 LTS Python
[Python] How to install OpenCV on Anaconda [Windows]
I want to use Python in the environment of pyenv + pipenv on Windows 10
Prepare a development environment that is portable and easy to duplicate without polluting the environment with Python embeddable (Windows)
Think about how to program Python on the iPad
How to embed mod_wsgi into Apache on Python Windows
How to build a Django (python) environment on docker
How to enjoy Python on Android !! Programming on the go !!
How to run Django on IIS on a Windows server
How to build a Python environment on amazon linux 2
How to install Python [Windows]
How to build a new python virtual environment on Ubuntu
How to run a Python file at a Windows 10 command prompt
[Hyperledger Iroha] Notes on how to use the Python SDK
Don't lose to Ruby! How to run Python (Django) on Heroku
Detailed explanation How to run the sample code of UNIX programming 3rd edition on Mac
Build python environment on windows
How to run Notepad ++ Python
How to get into the python development environment with Vagrant
I tried changing the python script from 2.7.11 to 3.6.0 on windows10
Run the output code on the local web server as "A, pretending to be B" in python
How to touch Jupyter Notebook without polluting the environment other than Pythonista, or how to touch Ruby with Jupyter Notebook without polluting the environment other than Rubyist
Make Pandas available on Jupyter in the shortest possible time on your new Mac without polluting the environment
How to rebuild python environment from pyenv on Mac environment (El Capitan)
How to use jupyter notebook without polluting your environment with Docker
How to build a Python environment using Virtualenv on Ubuntu 18.04 LTS
[Python + heroku] From the state without Python to displaying something on heroku (Part 1)
[Python + heroku] From the state without Python to displaying something on heroku (Part 2)
How to update the python version of Cloud Shell on GCP
How to set up the development environment of ev3dev [Windows version]
Everything from building a Python environment to running it on Windows
Python environment construction memo on Windows 10
Python 3.6 on Windows ... and to Xamarin.
Anaconda python environment construction on Windows 10
Install python2.7 on windows 32bit environment
How to install pycrypto on Windows
How to deploy django-compressor on Windows
How to get the Python version
How to run matplotlib on heroku
[Python3] Development environment construction << Windows edition >>
[Python] How to import the library
Install Python development environment on Windows 10
How to install music 21 on windows
How to run the practice code of the book "Creating a profitable AI with Python" on Google Colaboratory
Put Cabocha 0.68 on Windows and try to analyze the dependency with Python
How to easily switch the virtual environment created by Conda on Jupyter
Steps to create a Python virtual environment with VS Code on Windows
How to install python package in local environment as a general user
How to make Selenium as light as possible
How to access environment variables in Python
Python 2.7, 3.4, 3.5 extension module build environment on Windows
How to read pydoc on python interpreter
Steps to install Python environment on Ubuntu
How to use Google Assistant on Windows 10