You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched the issues of this repo and believe that this is not a duplicate.
I have searched the documentation and believe that my question is not covered.
Feature Request
Poetry is a very useful tool, not just for developing Python packages, but also for managing Python dependencies when developing in general (as a replacement tool for requirements.txt for example).
In developing environments, a very useful tool is to be able to append permanently to the PYTHONPATH.
For example, when working with Jupyter (standard in data science projects), the code is being executed from the folder where the Jupyter notebook is, so if it isn't in the project's root directory, importing code from your own code will fail. See a detailed example in my SO question.
The feature I am suggesting is equivalent to virtualenvwrapper add2virtualenv so it will be possible to permanently add to the PYTHONPATH of poetry-managed environments.
@eliorc I'm not sure if this (modifying/extending PYTHON PATH) is something poetry will implement. You could consider building a plugin.
That said, in your SO scenario, simply doing poetry install will suffice as the current project is installed as an editable. And as per your structure this will make src available as a python package, ie. import src, thanks to poetry discovering the package.
That said, even in cases where you are not interested in packaging, I'd recommend you move the contents of src into src/my_module and add the following to your pyproject.toml.
@eliorc I'm not sure if this (modifying/extending PYTHON PATH) is something poetry will implement. You could consider building a plugin.
That said, in your SO scenario, simply doing poetry install will suffice as the current project is installed as an editable. And as per your structure this will make src available as a python package, ie. import src, thanks to poetry discovering the package.
That said, even in cases where you are not interested in packaging, I'd recommend you move the contents of src into src/my_module and add the following to your pyproject.toml.
Seems to work as written in SO, I wanted to write a small version of the real problem but guess that didn't work well.
The real problem, is when you have a Jupyter notebook inside a directory which is not root, lets say
and you'll open your notebook (even if you launch the Jupyter server with poetry run jupyter notebook) when you will try to import from src it will fail. It happens across my company all the time and that is the problem I want to solve
Activity
abn commentedon Mar 31, 2022
@eliorc I'm not sure if this (modifying/extending PYTHON PATH) is something poetry will implement. You could consider building a plugin.
That said, in your SO scenario, simply doing
poetry installwill suffice as the current project is installed as an editable. And as per your structure this will makesrcavailable as a python package, ie.import src, thanks to poetry discovering the package.That said, even in cases where you are not interested in packaging, I'd recommend you move the contents of
srcintosrc/my_moduleand add the following to yourpyproject.toml.Your imports in your scripts need to be
import my_module.eliorc commentedon Mar 31, 2022
poetry install does not solve this when you are executing code not from the main directory
I actually already implemented this, thought of openning a PR after some testing
If this is more appropriate as a plugin, I'll see how I can do that
abn commentedon Mar 31, 2022
Here is your SO scenario recreated. Let me know what I am missing here.
eliorc commentedon Apr 1, 2022
@abn
Seems to work as written in SO, I wanted to write a small version of the real problem but guess that didn't work well.
The real problem, is when you have a Jupyter notebook inside a directory which is not root, lets say
and you'll open your notebook (even if you launch the Jupyter server with
poetry run jupyter notebook) when you will try to import fromsrcit will fail. It happens across my company all the time and that is the problem I want to solveabn commentedon Apr 1, 2022
I suspect that's because of the interpreter used by your notebook kernel. If you set it to your project's virtualenv, it should work.
You could also try adding jupyter as a dev dependency so that when you run
poetry run jupyterthe default interpreter is your project's.Otherwise, it will reuse the system-wide install of jupyter and whatever python instance it discovers.
github-actions commentedon Mar 2, 2024
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.