Two years ago, referring to a good article for Mac "How to get started with the Python project in 2018", WSL (Windows Subsystem for) on windows 10 Prepared a modern linux python environment (at that time) on Linux) (Article: Prepare a modern Python environment by hitting a command about 10 lines ). I'm still using the environment after updating it at that time, but since I've been using Mac for scala / java business, I decided to adopt it for building a python environment that is more compatible with the Mac method. .. In conclusion, I thought that this approach was definitely possible considering maintainability. It's a general-purpose approach regardless of language, so even beginners who need to use python and javascript in the near future should take on the challenge even when they have time.
--Introduce homebrew using WSL version ubuntu --Introduce anyenv from homebrew. --Put pyenv from anyenv and change package management from pipenv to poetry.
Using anyenv takes a lot of work, but I wanted to manage the version of nodejs etc. in the same way, so I challenged it. It seems that there is asdf as an option to build a more diverse environment, but I wonder if that will be adopted about two years after it withers.
Personally, the big change from two years ago is that the ratio of using vscode has increased. ... Before that, I used sublime text because I had to deal with billions of lines of text files. Nowadays, vscode is the editor for both Mac and windows. So I wrote the following article. If you are vscode + python, please take a look here as well. Realize an environment close to Mac easily with Windows 10 (wsl + vscode + homebrew)
There are only a few lines of command differences between Mac and windows wsl (ubuntu). Recently, the window10 machine of my personal computer is not working well and I am about to die, so when I set my personal computer to mac only, I thought I should write the difference on Mac.
Homebrew can be easily installed in the WSL version of ubuntu. Below, the installation procedure to ubuntu in the initial state
.sh
sudo apt update
sudo apt upgrade
sudo apt install linuxbrew-wrapper build-essential
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
echo 'eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)' >> ~/.bashrc
source ~/.bashrc
From here on, the procedure is almost the same as for Mac. Thank you. Include anyenv and anyenv convenience plugins. Some plugins aren't needed for pyenv, but be prepared for days when you use other languages.
brew install anyenv
anyenv init
echo 'eval "$(anyenv init -)"' >> ~/.bashrc
exec $SHELL -l
anyenv install --init
anyenv -v
mkdir -p $(anyenv root)/plugins
git clone https://github.com/znz/anyenv-update.git $(anyenv root)/plugins/anyenv-update
git clone https://github.com/znz/anyenv-git.git $(anyenv root)/plugins/anyenv-git
anyenv update
There are some steps specific to ubuntu for wsl here. However, I just click the following command.
If the version of ubuntu changes, the procedure may change. In that case, let's do our best by google with one of the keywords pyenv / ubuntu / poetry
. In the article two years ago, the procedure changed slightly about once every six months and I updated the article, so I will check it at the same frequency this time and update this article as appropriate (I feel like I do not write much) ..
.sh
anyenv install pyenv
exec $SHELL -l
sudo apt-get install -y libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev
pyenv install 3.8.2
pyenv global 3.8.2
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python
source $HOME/.poetry/env
It should look like this.
userid@DESKTOP-YourID:~$ poetry
Poetry version 1.0.5
USAGE
poetry [-h] [-q] [-v [<...>]] [-V] [--ansi] [--no-ansi] [-n] <command> [<arg1>] ... [<argN>]
ARGUMENTS
<command> The command to execute
<arg> The arguments of the command
GLOBAL OPTIONS
-h (--help) Display this help message
-q (--quiet) Do not output any message
-v (--verbose) Increase the verbosity of messages: "-v" for normal output, "-vv" for more verbose output and "-vvv" for debug
-V (--version) Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n (--no-interaction) Do not ask any interactive question
AVAILABLE COMMANDS
about Shows information about Poetry.
add Adds a new dependency to pyproject.toml.
build Builds a package, as a tarball and a wheel by default.
cache Interact with Poetry's cache
check Checks the validity of the pyproject.toml file.
config Manages configuration settings.
debug Debug various elements of Poetry.
env Interact with Poetry's project environments.
export Exports the lock file to alternative formats.
help Display the manual of a command
init Creates a basic pyproject.toml file in the current directory.
install Installs the project dependencies.
lock Locks the project dependencies.
new Creates a new Python project at <path>.
publish Publishes a package to a remote repository.
remove Removes a package from the project dependencies.
run Runs a command in the appropriate environment.
search Searches for packages on remote repositories.
self Interact with Poetry directly.
shell Spawns a shell within the virtual environment.
show Shows information about packages.
update Update the dependencies as according to the pyproject.toml file.
version Shows the version of the project or bumps it when a valid bump rule is provided.
userid@DESKTOP-YourID:~$ python
Python 3.8.2 (default, Apr 4 2020, 23:48:47)
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
I put nodejs in addition to python on my PC, but it is clean on brew (hugo is introduced separately for the purpose of blogging). I think this is a good point of this method.
$ brew list
anyenv hugo patchelf
The official document has been translated into Japanese (below), so it seems good to start here. https://cocoatomo.github.io/poetry-ja/basic-usage/
It is important to manage the version of pyhon and packages by the procedure described here, such as when using python for web development with tight delivery time, if there is even one package that does not work. For data engineer / data science projects, you need to connect to a rather designated (often legacy) database. When connecting to an older database, the linux version of the driver may not be possible. If pyenv is completed on wsl, coexistence with winpython is of course no problem. Let's use winpython as appropriate to secure the option of database connection via ODBC etc. With the portable version, there is no worry that the environment will get dirty, so with python alone, winpython, which also introduces anaconda and pandas / numpy without permission, may be the strongest. However, when it comes to linking with other tools via the shell, I still want a wsl pyenv.
If you follow this procedure, you can easily manage the version of nodejs. If you want to install the latest version of nodejs at the moment, follow the steps below.
anyenv install nodenv
exec $SHELL -l
touch $(nodenv root)/default-packages
nodenv install 13.2.0
nodenv global 13.12.0
You can check the version with node -v
.
Recommended Posts