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.
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.
First, organize the requirements for creating a script.
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.
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.
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.
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.
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 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
}
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
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"
}
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.
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
}
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
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.
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:
Install vundle
mkdir ~/.vim
mkdir ~/.vim/bundle
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
:PluginInstall
: PlugInstall
on vim.
Recommended Posts