Windows poetry add to path

Introduction #

Poetry is a tool for dependency management and packaging in Python.
It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.
Poetry offers a lockfile to ensure repeatable installs, and can build your project for distribution.

System requirements #

Poetry requires Python 3.8+. It is multi-platform and the goal is to make it work equally well
on Linux, macOS and Windows.

Installation #

Warning

Poetry should always be installed in a dedicated virtual environment to isolate it from the rest of your system.
In no case, it should be installed in the environment of the project that is to be managed by Poetry.
This ensures that Poetry’s own dependencies will not be accidentally upgraded or uninstalled.
(Each of the following installation methods ensures that Poetry is installed into an isolated environment.)

Note

If you are viewing documentation for the development branch, you may wish to install a preview or development version of Poetry.
See the advanced installation instructions to use a preview or alternate version of Poetry.

pipx is used to install Python CLI applications globally while still isolating them in virtual environments.
pipx will manage upgrades and uninstalls when used to install Poetry.

  1. Install Poetry

  2. Install Poetry (advanced)

    pipx can install different versions of Poetry, using the same syntax as pip:

    pipx install poetry==1.2.0
    

    pipx can also install versions of Poetry in parallel, which allows for easy testing of alternate or prerelease
    versions. Each version is given a unique, user-specified suffix, which will be used to create a unique binary name:

    pipx install --suffix=@1.2.0 poetry==1.2.0
    poetry@1.2.0 --version
    
    pipx install --suffix=@preview --pip-args=--pre poetry
    poetry@preview --version
    

    Finally, pipx can install any valid pip requirement spec, which
    allows for installations of the development version from git, or even for local testing of pull requests:

    pipx install --suffix @master git+https://github.com/python-poetry/poetry.git@master
    pipx install --suffix @pr1234 git+https://github.com/python-poetry/poetry.git@refs/pull/1234/head
    
  3. Update Poetry

  4. Uninstall Poetry

Enable tab completion for Bash, Fish, or Zsh #

poetry supports generating completion scripts for Bash, Fish, and Zsh.
See poetry help completions for full details, but the gist is as simple as using one of the following:

Bash #

Auto-loaded (recommended) #

poetry completions bash >> ~/.bash_completion

Lazy-loaded #

poetry completions bash > ${XDG_DATA_HOME:-~/.local/share}/bash-completion/completions/poetry

Fish #

poetry completions fish > ~/.config/fish/completions/poetry.fish

Zsh #

poetry completions zsh > ~/.zfunc/_poetry

You must then add the following lines in your ~/.zshrc, if they do not already exist:

fpath+=~/.zfunc
autoload -Uz compinit && compinit

Oh My Zsh #

mkdir $ZSH_CUSTOM/plugins/poetry
poetry completions zsh > $ZSH_CUSTOM/plugins/poetry/_poetry

You must then add poetry to your plugins array in ~/.zshrc:

prezto #

poetry completions zsh > ~/.zprezto/modules/completion/external/src/_poetry

Note

You may need to restart your shell in order for these changes to take effect.

Пригласить эксперта

просто укажите полный путь к файлу poetrry в кавычках

Ваш случай — это наглядный пример преимущества чтения официальной документации над просмотром видосиков от ютубных гуру. Почитайте, там и путь установки по умолчанию написан. Скорее всего у Вас туда всё и установлено, только в path не добавлено. Ну или поиском по диску файл ищите!
https://python-poetry.org/docs/#windows-powershell…


  • Показать ещё
    Загружается…

09 окт. 2023, в 11:29

30000 руб./за проект

09 окт. 2023, в 11:22

400000 руб./за проект

09 окт. 2023, в 11:14

1500 руб./за проект

Минуточку внимания

Poetry is a tool that facilitates creating a Python virtual environment based on the project dependencies. You can declare the libraries your project depends on, and Poetry will install and update them for you.

Project dependencies are recorded in the pyproject.toml file that specifies required packages, scripts, plugins, and URLs. See the pyproject reference for more information about its structure and format.

To use Poetry in PyCharm, you need to install it on your machine and create a specific Python environment.

Install Poetry

  1. Open Terminal (on macOS and Linux) or PowerShell (on Windows) and execute the following command:

    curl -sSL https://install.python-poetry.org | python3 —

    (Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py —

    curl -sSL https://install.python-poetry.org | python3 —

  2. On macOS and Windows, the installation script will suggest adding the folder with the poetry executable to the PATH variable. Do that by running the following command:

    export PATH=»/Users/jetbrains/.local/bin:$PATH»

    $Env:Path += «;C:\Users\jetbrains\AppData\Roaming\Python\Scripts»; setx PATH «$Env:Path»

    Don’t forget to replace jetbrains with your username!

  3. To verify the installation, run the following command:

    poetry —version

    You should see something like Poetry (version 1.2.0).

For more information, refer to the Poetry Installation Instructions.

Create a Poetry environment

  1. Do one of the following:

    • Click the Python Interpreter selector and choose Add New Interpreter.

    • Press Control+Alt+S to open Settings and go to . Click the Add Interpreter link next to the list of the available interpreters.

    • Click the Python Interpreter selector and choose Interpreter Settings. Click the Add Interpreter link next to the list of the available interpreters.

  2. Select Add Local Interpreter.

  3. In the left-hand pane of the Add Python Interpreter dialog, select Poetry Environment.

    creating a poetry environment

  4. The following actions depend on whether you want to create a new Poetry environment or to use an existing one.

    New Poetry environment
    • Select Poetry Environment.

    • Choose the base interpreter from the list, or click Choose the base interpreter and find the desired Python executable in your file system.

    • If your project contains pyproject.toml, you can choose whether you want to install the packages listed in it by enabling or disabling the Install packages from pyproject.toml checkbox. By default, the checkbox is enabled.

    • If PyCharm doesn’t detect the poetry executable, specify the following path in the Poetry executable field, replacing jetbrains with your username:

      /Users/jetbrains/Library/Application Support/pypoetry/venv/bin/poetry

      C:\Users\jetbrains\AppData\Roaming\pypoetry\venv\Scripts\poetry.exe

      /home/jetbrains/.local/bin/poetry

    Existing Poetry environment
    • Make sure that the project directory contains a pyproject.toml file.

    • Select Existing environment. Then expand the Interpreter list and choose the desired interpreter.

    • If the desired interpreter is not on the list, clickApp general ellipsis, and then browse for the Python executable within the previously configured Poetry environment.

    The selected Poetry environment will be reused for the current project.

  5. Click OK to complete the task.

If you select a poetry environment when creating a new Python project, PyCharm adds two files to your project:

  • pyproject.toml: specifies the project requirements

  • poetry.lock: records changes in the projects requirements

Each time you modify the pyproject.toml file, PyCharm notifies you and offers two actions: to record the changes in the poetry.lock file (poetry lock) or to record the changes and install the unsatisfied requirements (poetry update).

Lock or update poetry

Create a Poetry environment using pyproject.toml

  1. When you open a project that contains pyproject.toml, but no project interpreter is configured, PyCharm suggests that you create a Poetry environment.

    pyproject.toml detected

  2. Click Set up a poetry environment using pyproject.toml if you want PyCharm to configure Poetry for you automatically. Alternatively, you can click Configure Python interpreter to follow the standard workflow.

  3. If PyCharm cannot autodetect the Poetry executable, specify the path to it and click OK.

A new Poetry environment will be configured for your project and the packages listed in pyproject.toml will be installed.

Last modified: 27 September 2023

Generally the path of Poetry should be added to the ENV variable PATH.

1. use which find where is poetry installed just after you installed poetry.

which poetry

# $HOME/.local/bin/poetry  # if installed with Brew
# maybe elsewhere: "$HOME/.poetry/bin:$PATH"

In fact, it reminds users to add the path to the shell configuration file in the output of the Poetry installation.

Installing Poetry (1.2.2): Done

Poetry (1.2.2) is installed now. Great!

To get started you need Poetry’s bin directory
(/home/shell/.local/bin) in your PATH environment variable.

Add export PATH="/home/shell/.local/bin:$PATH" to your shell
configuration file.

Alternatively, you can call Poetry explicitly with
/home/shell/.local/bin/poetry.

2. find what kind of shell you are using:

echo $SHELL

# /usr/bin/zsh    # many people use zsh or oh-my-zsh
  # For zsh, put stuff in ~/.zshrc, which is always executed.
  # For bash, put stuff in ~/.bashrc, and make ~/.bash_profile source it.

3. add the Poetry executable path to $PATH and add it to a shell startup configuration file to init it every time you start with that shell:

export SHELL_RCFILE="~/.zshrc"
echo "export POETRY_PATH=$HOME/.local/bin/ && export PATH="$POETRY_PATH:$PATH" >> $SHELL_RCFILE

Reference: zsh, bash startup files loading

Poetry is a package manager for Python that helps developers manage their dependencies and projects. If you’re using Pycharm as your Python IDE and Windows with WSL2 as your operating system, you may encounter some issues when configuring Poetry environments in Pycharm. This tutorial will guide you through the steps to configure Poetry environments in Pycharm on Windows + WSL2.

Method 1: Use Pycharm Interpreter from WSL2

  1. Open your project in Pycharm.

  2. Click on File > Settings > Project: <project_name> > Python Interpreter.

  3. Click on the gear icon and select Add....

  4. Select SSH Interpreter.

  5. In the Configure Remote Python Interpreter dialog, click on the SSH Credentials button.

  6. In the SSH Credentials dialog, click on the + button and add your WSL2 credentials.

  7. Once added, select the WSL2 interpreter from the list and click OK.

  8. In the Configure Remote Python Interpreter dialog, select the Python interpreter path option and enter the path to your Python interpreter in WSL2.

    Example: /usr/bin/python3

  9. Click OK to close the dialog and save the interpreter.

  10. Now, you can create a new Poetry environment by opening the terminal in Pycharm and running the following command:

    poetry env use /usr/bin/python3
  11. Activate the Poetry environment by running the following command:

    source /path/to/poetry/envs/<env_name>/bin/activate
  12. You can now install packages using Poetry and they will be installed in the activated environment.

    Example:

  13. To deactivate the environment, run the following command:

That’s it! You have now configured Poetry environments in Pycharm with Windows + WSL2 using Pycharm Interpreter from WSL2.

Method 2: Use Windows Path for Poetry

Using Windows Path for Poetry

  1. Install Poetry on your Windows machine by running the following command in your terminal:

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

  1. Install WSL2 and set it up on your Windows machine.

  2. Open Pycharm and create a new project.

  3. Open the terminal in Pycharm and activate the virtual environment by running the following command:

poetry shell

  1. Install any packages you need in your project by running the following command:

poetry add <package-name>

  1. To use the Windows path for Poetry, you need to add the following line to your .bashrc or .zshrc file:

export PATH="$PATH:$HOME/.poetry/bin"

  1. Restart your terminal or run the following command to apply the changes:

source ~/.bashrc or source ~/.zshrc

  1. In Pycharm, go to File > Settings > Project > Project Interpreter.

  2. Click on the gear icon and select Add.

  3. Select Poetry Environment and click OK.

  4. Choose the virtual environment you created earlier and click OK.

  5. Pycharm will now use the virtual environment created by Poetry.

  6. To verify that everything is working correctly, run the following command in your terminal:

which python

  1. The output should show the path to the Python executable in the virtual environment.

  2. Congratulations! You have successfully configured Poetry environments in Pycharm with Windows + WSL2 using the Windows path for Poetry.

Method 3: Use Remote Interpreter from WSL2

Step 1: Install Pycharm and WSL2

If you have not installed Pycharm and WSL2, you can follow the official documentation to install them.

Step 2: Create a Poetry Environment in WSL2

Open a terminal in WSL2 and create a new poetry environment:

poetry new myproject
cd myproject
poetry shell

Step 3: Install Pycharm WSL Remote Interpreter Plugin

In Pycharm, go to File -> Settings -> Plugins, search for WSL Remote Interpreter and install the plugin.

Step 4: Configure Remote Interpreter

Go to File -> Settings -> Project -> Python Interpreter, click on the gear icon and select Add.... In the Add Python Interpreter window, select SSH Interpreter and fill in the following information:

  • Host: localhost
  • Port: 22
  • Username: your WSL2 username
  • Auth type: Key pair
  • Private key file: path to your WSL2 private key file

Click on Test Connection to make sure the connection is successful. Then click on OK to save the interpreter.

Step 5: Configure Project Interpreter

Go to File -> Settings -> Project -> Python Interpreter, click on the gear icon and select Add.... In the Add Python Interpreter window, select SSH Interpreter and select the interpreter you just configured in the previous step.

Step 6: Configure Poetry Environment

Go to File -> Settings -> Project -> Project Interpreter, select the interpreter you just configured, and click on the gear icon. Select Show All... and click on the + icon to add a new path. Enter the path to your poetry environment in WSL2, for example:

/home/yourusername/myproject/.venv/bin/python

Click on OK to save the path.

Step 7: Activate Poetry Environment

In Pycharm, open a terminal and activate the poetry environment:

source /path/to/your/project/.venv/bin/activate

Step 8: Install Dependencies

Install the dependencies for your project using poetry:

Step 9: Run Your Project

You can now run your project in Pycharm using the configured interpreter and poetry environment.

That’s it! You have successfully configured Poetry environments in Pycharm with Windows + WSL2 using remote interpreter.

  • Windows photo viewer не найден указанный модуль
  • Windows photo gallery for windows 10
  • Windows photo viewer как удалить
  • Windows photo editor for windows 10
  • Windows photo viewer как включить