Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
python-poetry
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
python-poetry
Commits
56cf6cc7
Unverified
Commit
56cf6cc7
authored
Aug 15, 2020
by
Kelton Bassingthwaite
Committed by
GitHub
Aug 15, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
doc: expand information on venv usage
Resolves: #2333
parent
3f7545d6
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
0 deletions
+49
-0
docs/docs/basic-usage.md
+49
-0
No files found.
docs/docs/basic-usage.md
View file @
56cf6cc7
...
...
@@ -64,6 +64,55 @@ $ poetry add pendulum
It will automatically find a suitable version constraint
**and install**
the package and subdependencies.
## Using your virtual environment
By default, poetry creates a virtual environment in
`{cache-dir}/virtualenvs`
(
`{cache-dir}\virtualenvs`
on Windows).
You can change the
[
`cache-dir`
](
/docs/configuration/#cache-dir
)
value by editing the poetry config.
Additionally, you can use the
[
`virtualenvs.in-project`
](
/docs/configuration/#virtualenvs.in-project
)
configuration variable
to create virtual environment within your project directory.
There are several ways to run commands within this virtual environment.
### Using `poetry run`
To run your script simply use
`poetry run python your_script.py`
.
Likewise if you have command line tools such as
`pytest`
or
`black`
you can run them using
`poetry run pytest`
.
### Activating the virtual environment
The easiest way to activate the virtual environment is to create a new shell with
`poetry shell`
.
To deactivate the virtual environment and exit this new shell type
`exit`
.
To deactivate the virtual environment without leaving the shell use
`deactivate`
.
!!!note
**Why a new shell?**
Child processes inherit their environment from their parents, but do not share
them. As such, any modifications made by a child process, is not persisted after
the child process exits. A Python application (Poetry), being a child process,
cannot modify the environment of the shell that it has been called from such
that an activated virtual environment remains active after the Poetry command
has completed execution.
Therefore, Poetry has to create a sub-shell with the virtual envrionment activated
in order for the subsequent commands to run from within the virtual environment.
Alternatively, to avoid creating a new shell, you can manually activate the
virtual environment by running
`source {path_to_venv}/bin/activate`
(
`source {path_to_venv}\Scripts\activate.bat`
on Windows).
To get the path to your virtual environment run
`poetry env info --path`
.
You can also combine these into a nice one-liner,
`source $(poetry env info --path)/bin/activate`
To deactivate this virtual environment simply use
`deactivate`
.
| | POSIX Shell | Windows | Exit/Deactivate |
|-------------------|------------------------------------------------|---------------------------------------------|-----------------|
| New Shell |
`poetry shell`
|
`poetry shell`
|
`exit`
|
| Manual Activation |
`source {path_to_venv}/bin/activate`
|
`source {path_to_venv}\Scripts\activate.bat`
|
`deactivate`
|
| One-liner |
```source`poetry env info --path`/bin/activate```
| |
`deactivate`
|
### Version constraints
In our example, we are requesting the
`pendulum`
package with the version constraint
`^1.4`
.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment