Try Poerty on Windows

The original article is here

It's about Python package management and tools for managing virtual environments.

I use Pipenv normally, but I still used poetry properly. I haven't done so, so I gave it a try.

environment

This goal

Create project folders for 3.7 and 2.7 with poetry, run poetry run python --version in each folder, and if the displayed Python version is different, it will be successful.

poetry installation

Recommended in Official poetry installation method

curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python

With this method, there are the following problems in Windows.

First of all, regarding the mysterious python.exe problem, this is due to the ** app execution alias ** that seems to have been introduced relatively recently in Windows 10. When you open Windows Settings-> Apps and Features-> App Execution Alias, you will find ** App Installer (python.exe) ** and ** App Installer (python3.exe) **, so turn them off. (Although you can change the priority of the paths)

アプリ実行エイリアスの設定

Regarding the second point, there is no choice but to change to another installation method. Although it is deprecated in the documentation, it will be installed user-globally with the pip command, just like Pipenv. Let's wait for the recommended method to install it nicely. With this method, you need to manually set the path to the folder containing the two files poetry and poetry.bat (this time it was installed in Python 3.7, so % APPDATA% \ Python \ Python37 \ Scripts).

  1. Run py -3 -m pip install --user --pre poetry in a shell such as Powershell
  2. (User this time) Add % APPDATA% \ Python \ Python37 \ Scripts to the environment variable PATH
  3. Reboot the shell
  4. Run poetry --version on the shell, this time it will return Poetry version 1.0.0b8

This completes the poetry installation.

Poetry setting change

poetry also manages the virtual environment (virtualenv), but by default the location of the virtual environment is % USERDIR% \ Local \ pypoetry \ Cache \ virtualenvs. Since it is easier to create a virtual environment in the project folder for use with Visual Studio Code etc., I will change some poetry settings.

> poetry config --list
cache-dir = "C:\\Users\\xxxxxxxx\\AppData\\Local\\pypoetry\\Cache"
virtualenvs.create = true
virtualenvs.in-project = false    (← I want to make this true)
virtualenvs.path = "{cache-dir}\\virtualenvs"

> poetry config virtualenvs.in-project true
> poetry config --list
cache-dir = "C:\\Users\\xxxxxxxx\\AppData\\Local\\pypoetry\\Cache"
virtualenvs.create = true
virtualenvs.in-project = true
virtualenvs.path = "{cache-dir}\\virtualenvs"

If you let poetry create a virtual environment in this state, it will be created in [project folder] \ .venv.

Project switching test

Now let's create one Python 3.7 and one 2.7 project using poetry. Since poetry is installed on Python 3.7 this time, a project for Python 3.7 will be created unless otherwise specified.

> poetry new py3test
Created package py3test in py3test

> cd py3test
> poetry install
Creating virtualenv py3test in C:\Work\py3test\.venv
Updating dependenciesResolving dependencies... (0.4s)
(pytest and dependent packages will be installed)

> poetry run python --version
Python 3.7.5

Next, create a project for Python 2.7. The points are the following two points.

--Change the dependent Python version to 2.7 --pytest supports Python 2.7 up to 4.6 series

> cd ..
> poetry new py2test
Created package py2test in py2test

> cd py2test

[Important] Here pyproject.Edit toml.
python = "^3.7" → python = "^2.7"
pytest = "^5.2" → pytest = "^4.6"

> poetry env use C:\Python27\python.exe
Creating virtualenv py2test in C:\Work\py2test\.venv
Using virtualenv: C:\Work\py2test\.venv

> poetry install
Updating dependencies
Resolving dependencies... (1.1s)
(pytest and dependent packages will be installed)

> poetry run python --version
Python 2.7.17

For confirmation, let's move to the project for Python 3.7.

> cd ..\py3test
> poetry run python --version
Python 3.7.5

You can see that the Python virtual environment is used properly depending on the current folder. This is the end of the experiment.

Summary

I was able to operate the virtual environment with poetry using Py Launcher instead of pyenv on Windows. I think you can probably use it this way, but for now I think Pipenv is still easier on Windows.

Recommended Posts

Try Poerty on Windows
Try FEniCS on Windows!
Try using OpenCV on Windows
Try using Bash on Windows 10 2 (TensorFlow installation)
Pylint on Windows Atom
Linux (WSL) on Windows
Use pyvenv on Windows
Anaconda on Windows Terminal
Install Anaconda on Windows 10
python basic on windows ②
Install python on windows
Install pycuda on Windows10
Build TensorFlow on Windows
Build XGBoost on Windows
Install pygraphviz on Windows 10
Use Ansible on Windows
Try NeosVR on Linux
Install Chainer 1.5.0 on Windows
Use QuTiP on Windows
Use pip on Windows
Try deepdream on Mac
Try using E-Cell 4 on Windows 7 or Mac OS X
Install Numpy on virtualenv on Windows
Set-enable Python virtualenv on Windows
Run Jupyter on Ubuntu on Windows
Run Openpose on Python (Windows)
Before trying Veriloggen on Windows
Install cvxpy on windows, Anaconda
Python + Kivy development on Windows
F2py on Miniconda for Windows
Sphinx-autobuild (0.5.2) on Windows7, Python 3.5.1, Sphinx 1.3.5
Operate ubuntu on VScode (windows10)
Build Python environment on Windows
Try "100 knocks on data science" ①
Django environment development on Windows 10
Install Chainer 1.6 (GPU) on Windows 7.
Build python environment on windows
Set up Polyglot on Windows
I ran python on windows
[Tensorflow] Tensorflow environment construction on Windows 10
Notes on installing Anaconda 3 on Windows
[Python] [Chainer] [Windows] Install Chainer on Windows
Use Python on Windows (PyCharm)
Run Jupyter Notebook on windows
Use Linux on Windows 10 (WSL2)
Blogging with Pelican on Windows
Build an environment on windows10 where you can try MXNet
Python environment construction memo on Windows 10
Remove ubuntu installed on Windows 10 machine
Try running tensorflow on Docker + anaconda
Python 3.6 on Windows ... and to Xamarin.
Installing Kivy on Windows10 64bit Python3.5
Try using Pillow on iPython (Part 1)
Anaconda python environment construction on Windows 10
How to use Dataiku on Windows
Drawing graphs on Windows10 + Julia + PyPlot
Try installing OpenAM on Amazon Linux
Install python2.7 on windows 32bit environment
Install xgboost (python version) on Windows
Try using Pillow on iPython (Part 2)
Install Python on Windows + pip + virtualenv