[PYTHON] I want to do pyenv + pipenv on Windows

Summary

Hi, I'm M1 who was entrusted with a certain course for B1 and B2 students. The content is to teach you how to use Tensorflow ** 1.12 **, which means to look at ** Environmental Hell ** and ** Compatibility Hell **.

The purpose of this article is to create a state where ** Windows users ** can develop, in order to create an environment where they can start development for the time being.

First of all, I wrote powershell script like this. You can get a nice environment by running this guy.

Preface: Infinite development environment

The development environment is different for each person, and I use Manjaro Linux x Docker x Emacs x LSP, which is a fairly rigid environment, but this is not the only one that is abnormal.

As a university class, I often teach Emacs (~~ to increase my dislike of Emacs ~~), but perhaps because of that, the current situation is that editors such as vim, neovim, gvim, or VSCode are all varieties. It exists as a problem.

In addition, when OS options such as macOS, which is famous for its glitter, Ubuntu, which looks like a crazy person, and Windows 8 (/10), which I don't know but sells there, come in, the combination explosion is dangerous.

Organize requirements

First, organize the requirements for creating a script.

  1. Being a Windows 10 user

We will create a separate tutorial for Mac and Linux, and update to 10 for Windows. Fortunately, the university I belong to distributes Windows 10, so Windows 8 / 8.1 will have a policy of having it updated.

  1. Powershell can be used

WSL, Bash on Ubuntu, and Hyper-V cannot be used because they can be disabled due to performance or software engagement. With Powershell ... I'm sure it's okay.

  1. You are using some ** decent ** editor

Recently, LSP (language-server-protocol) has been growing as a popular complement / check tool. For example, popular editors such as VSCode, Vim, and Emacs support LSP. I'm sure you're using an editor that can use this. ~~ I don't know about notepads ~~

With this requirement, we will write a script.

Created script and how to use

python_install_on_windows.ps1


# installation scoop
try {
 scoop --version
} finally {
  Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
  Set-ExecutionPolicy RemoteSigned -scope CurrentUser
}

# install some utility applications
scoop install python wget curl git
python --version
pip install pipenv

# install pyenv environment
if (!(get-command pyenv -errorAction SilentlyContinue)) {
  pip install pyenv-win --target $env:USERPROFILE\.pyenv
  [Environment]::SetEnvironmentVariable("PATH", "$env:Path;$env:USERPROFILE\.pyenv\pyenv-win\bin;$env:USERPROFILE\.pyenv\pyenv-win\shims", "User")
  $env:PATH = "$env:Path;$env:USERPROFILE\.pyenv\pyenv-win\bin;$env:USERPROFILE\.pyenv\pyenv-win\shims"
}

pyenv install 3.6.8-amd64

# create temporary file
if (!(Test-Path $env:USERPROFILE\.cache)) {
  New-Item $env:USERPROFILE\.cache -ItemType Directory
}
if (!(Test-Path $env:USERPROFILE\.cache\tmp)) {
  New-Item $env:USERPROFILE\.cache\tmp -ItemType Directory
}

# create project file
if (!(Test-Path $env:USERPROFILE\tensorflow_tutorial)) {
  New-Item $env:USERPROFILE\tensorflow_tutorial -ItemType Directory
}

# setup python environment
Set-Location $env:USERPROFILE\tensorflow_tutorial
pipenv install --python 3.6.8-amd64
pipenv install tensorflow==1.12.0 python-language-server[all] ipython

Save it in a convenient location and make the file properties executable as follows:

Then put this file on Powershell

./python_install_on_windows.ps1

If you run, it will be installed without permission, and C: \ Users \ <USername> \ tensorflow_tutorial will be created as a sample project.

What are you doing

After that, it will be an explanation of what you are doing.

What this script is doing is

--Installation of Windows package management system Scoop --Python installation --Installing Pyenv --Create a temporary folder for LSP --Creating a sample project

It has become.

Scoop installation

Scoop is a Unix-like tool for installing packages on a per-user basis. The advantages of this tool are ** no permissions required **, ** easy to install **, ** commands similar to Linux and macOS **.

# installation scoop
try {
 scoop --version
} finally {
  Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
  Set-ExecutionPolicy RemoteSigned -scope CurrentUser
}

Python installation

Now that you have Scoop installed, you can install ** general ** software / applications like Python.

git, curl, wget are commands that you want to know about B3, B4 or later, and git is sometimes asked about job hunting, so let's take this opportunity to learn.

# install some utility applications
scoop install python wget curl git
python --version

Install Pyenv

Pyenv is introduced for Python version control tools. There are various versions of Python such as 3.5 and 3.6, and this version is limited to Gorigori for ~~ shit ~~ Tensorflow.

There is also a way to install all the binaries individually and pass them through the path, but this time I will use a tool called Pyenv to reduce troublesome screen operations without using this.

# install pyenv environment
if (!(get-command pyenv -errorAction SilentlyContinue)) {
  pip install pyenv-win --target $env:USERPROFILE\.pyenv
  [Environment]::SetEnvironmentVariable("PATH", "$env:Path;$env:USERPROFILE\.pyenv\pyenv-win\bin;$env:USERPROFILE\.pyenv\pyenv-win\shims", "User")
  $env:PATH = "$env:Path;$env:USERPROFILE\.pyenv\pyenv-win\bin;$env:USERPROFILE\.pyenv\pyenv-win\shims"
}

Creating a temporary folder for LSP

The Language Server Protocol is simply code completion, defining a format for doing things like error messages, and, in rare cases, implementing it. In LSP, a system that analyzes code called a server will appear in addition to the editor. Below is a quote from VSCode documentation.

image.png

One of the motivations is, "Regardless of the language, let's send and receive code, error messages, and code documents like this, and it will be easier to implement complements in each editor."

By introducing this, you can standardize the settings around completion to some extent for editors with as many stars.

# create temporary file
if (!(Test-Path $env:USERPROFILE\.cache)) {
  New-Item $env:USERPROFILE\.cache -ItemType Directory
}
if (!(Test-Path $env:USERPROFILE\.cache\tmp)) {
  New-Item $env:USERPROFILE\.cache\tmp -ItemType Directory
}

Creating a sample project

As a sample project, create an environment of ** tensorflow 1.12 **.

Since tensorflow 1.12 only supports ** <= python3.6 ** environment, install ** 3.6.8 **.

Then create a project folder and then use pipenv, a ** package management tool ** (not a version) to install tensorflow, python-language-sever, and ipython under python 3.6.8. I will.

pip install pipenv
pyenv install 3.6.8-amd64

# create project file
if (!(Test-Path $env:USERPROFILE\tensorflow_tutorial)) {
  New-Item $env:USERPROFILE\tensorflow_tutorial -ItemType Directory
}

# setup python environment
Set-Location $env:USERPROFILE\tensorflow_tutorial
pipenv install --python 3.6.8-amd64
pipenv install tensorflow==1.12.0 python-language-server[all] ipython

Execution method

To run the sample project, for example for vim

pipenv run vim

Wake up in the form of. For VSCode, just open the tensorflow_tutorial folder and you're good to go.

Postscript: Example of vim configuration file

An example of a vim config file is here, but I don't have a long history of vim, so it's probably better to listen with a hashtag on Twitter.

To enable this configuration file, do the following:

  1. Install vundle

    mkdir ~/.vim
    mkdir ~/.vim/bundle
    git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
    
  2. :PluginInstall : PlugInstall on vim.

Recommended Posts

I want to do pyenv + pipenv on Windows
I want to use Python in the environment of pyenv + pipenv on Windows 10
I want to do Wake On LAN fully automatically
I want to do ○○ with Pandas
I want to use Linux on mac
I want to develop Android apps on Android
I want to do Dunnett's test in Python
I want to log file I / O on Linux
Library for "I want to do that" of data science on Jupyter Notebook
I want to develop an Android application on Android (debugging)
I want to find a popular package on PyPi
I want to AWS Lambda with Python on Mac!
[TensorFlow] I want to process windows with Ragged Tensor
I want to use OpenJDK 11 on Ubuntu Linux 18.04 LTS / 18.10
[ML Ops] I want to do multi-project with Python
I want to restart CentOS 8 on time every day.
I want to do something in Python when I finish
I want to solve Sudoku (Sudoku)
I ran python on windows
I want to do something like sort uniq in Python
I want to announce my graduation thesis on IPython Notebook
[AWS EC2] Settings you want to do on Amazon Linux 2
I tried changing the python script from 2.7.11 to 3.6.0 on windows10
How to use Dataiku on Windows
How to install pycrypto on Windows
I want to scrape images to learn
I want to copy yolo annotations
I want to debug with Python
How to install music 21 on windows
I tried to create a server environment that runs on Windows 10
I want to use shortcut translation like DeepL app on Linux
What to do if Python doesn't work on Git for Windows
MacBookPro Setup After all I want to do a clean installation
I want to do a full text search with elasticsearch + python
What to do if PyAudio cannot be installed on Python 3.7, 3.8, 3.9 on Windows
The quick action PDF creator on the Mac I want it on Windows
I want to automatically operate Chrome on Windows from a virtual machine (ubuntu) started using Vagrant
I want to pin Spyder to the taskbar
I want to detect objects with OpenCV
I want to output to the console coolly
Two things I was addicted to building Django + Apache + Nginx on Windows
I want to do it with Python lambda Django, but I will stop
I want to tweet on Twitter with Python, but I'm addicted to it
I want to print in a comprehension
I want to scrape them all together.
I want to handle the rhyme part1
[Kivy] How to install Kivy on Windows [Python]
I want to know how LINUX works!
I want to blog with Jupyter Notebook
Catalina: pyenv stuck on migration to zsh
If you want to use NumPy, Pandas, Matplotlib, IPython, SciPy on Windows
I want to handle the rhyme part3
Note: I want to do home automation with Home Assistant + Raspberry Pi + sensor # 1
I want to use jar from python
I want to display an image on Jupyter Notebook using OpenCV (mac)
I want to build a Python environment
I want to pip install with PythonAnywhere
I want to analyze logs with Python
I was addicted to Flask on dotCloud
I want to play with aws with python
I want to use IPython Qt Console