0

I have a local package, "mypackage", inside a venv environment. I successfully ran poetry install and I'm able to import it into Python sessions started inside of the same virtual env. Now I want to use mypackage in other projects and environments on my machine, specifically a pipenv environment setup for "myproject".

I followed the steps here: Install the latest version of my package from working directory into my local environment using Python's poetry But that leads to: Poetry could not find a pyproject.toml file in C:\Users\jonathan.biemond\PycharmProjects\myproject or its parents Do I need to have a pyproject.toml file in my project directory to import mypackage? myproject is not a package, just a local, undistributed project, so I don't have dependencies to maintain...

Here are my steps to setup mypackage:

  1. Create venv for mypackage: python -m venv
  2. pip install poetry
  3. poetry init from mypackage directory to create pyproject.toml for mypackage
  4. poetry install

Now I can use mypackage in the same virtual environment it was created in.

But I also want to use it in another virtual environment. Here are my steps to import mypackage:

  1. pipenv install numpy from myproject directory to create environment (and install numpy)
  2. Install poetry: (Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py -
  3. Install mypackage: poetry install mypackage
Jonathan Biemond
  • 359
  • 3
  • 12
  • 1
    You do not need Poetry to use a library created/managed by Poetry. -- It seems like the project that uses your Poetry-created library is itself managed by Pipenv, so use Pipenv to add this dependency on you `mylibrary`, no need to install Poetry if you already Pipenv. – sinoroc Mar 10 '23 at 11:42
  • But I do need a `setup.py` file to install a package using pip or pipenv. Which I don't have because mypackage is managed by Poetry. So I follow the steps here: https://github.com/python-poetry/poetry/discussions/1135#discussioncomment-145756 But same problem. – Jonathan Biemond Mar 10 '23 at 16:09
  • I am very confused. I think you probably should edit your question and rewrite with less confusing details. -- You do not need a `setup.py`, why do you suddenly mention `setup.py` out of nowhere? -- It seems to me like you have 2 "projects" in play. One project is the development of your library `mypackage`. This project and its virtual environment is "managed by "Poetry". And the other is `myproject` which is some kind of application maybe or at least a project that uses/dependes on `mylibrary` and is managed by Pipenv (including its virtual environment). Is that right? – sinoroc Mar 10 '23 at 16:46
  • You're correct, I don't have a good understanding of managing dependencies and packaging pythons and am not sure what details to include. --That's right I have 2 projects. `mypackage` is managed by Poetry, but the virtual environment is created/managed by `venv`. And yes `myproject` is managed by Pipenv. Both are locally on my machine. -- I mention `setup.py` because, I understood your suggestion to install `mypackage` using pipenv and pip/pipenv requires a package to have a `setup.py` file. – Jonathan Biemond Mar 10 '23 at 16:54
  • 1
    From your `myproject`, you should instruct Pipenv to add your `mypackage` as a dependency, I guess it seems it could be something like `pipenv install path/to/mylibrary`, or at least that is what I would try if I were in your case. – sinoroc Mar 10 '23 at 18:22
  • Yes, that works. Thank you! When I first tried that it failed, which I misinterpreted as meaning `mylibrary` needed to have a `setup.py` file. But I actually just pointed it to the wrong directory. – Jonathan Biemond Mar 10 '23 at 19:06

1 Answers1

0

No. In fact, as sinoroc points out in the comments:

You do not need Poetry to use a library created/managed by Poetry.

Instead use pip or pipenv to install mypackage to myproject with:

pipenv install path/to/mylibrary

Jonathan Biemond
  • 359
  • 3
  • 12