question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Running Python in shell does not find installed packages

See original GitHub issue

Issue

I want to use poetry shell to run python3 with the packages installed via poetry.

When I install the packages and run python3 from the shell, the packages are not found:

➜ poetry init
…
~/Desktop/test via 🐍 3.7.3
➜ poetry add fastapi uvicorn
Creating virtualenv test-py3.7 in /Users/werner/Library/Caches/pypoetry/virtualenvs
Using version ^0.42.0 for fastapi
Using version ^0.10.8 for uvicorn

Updating dependencies
Resolving dependencies... (4.9s)

Writing lock file


Package operations: 9 installs, 0 updates, 0 removals

  - Installing click (7.0)
  - Installing h11 (0.8.1)
  - Installing httptools (0.0.13)
  - Installing pydantic (0.32.2)
  - Installing starlette (0.12.9)
  - Installing uvloop (0.14.0)
  - Installing websockets (8.1)
  - Installing fastapi (0.42.0)
  - Installing uvicorn (0.10.8)

~/Desktop/test via 🐍 3.7.3 took 19s
➜ poetry run python3 -c "import fastapi"
email-validator not installed, email fields will be treated as str.
To install, run: pip install email-validator

~/Desktop/test via 🐍 3.7.3 took 2s
➜ poetry shell
Spawning shell within /Users/werner/Library/Caches/pypoetry/virtualenvs/test-py3.7

~/Desktop/test via test-py3.7 via 🐍 3.7.3
➜ python3 -c "import fastapi"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'fastapi'

The module is not found when inside the shell, but it is when I use poetry run.

Python 3 is 3.7.3 installed via pyenv:

➜ pyenv versions
  system
  3.6.5
* 3.7.3 (set by PYENV_VERSION environment variable)

Unless I’ve missed something obvious, I think this is the way this tool is intended to be used. I also know pipenv shell does the same, and from the documentation I don’t see any indication that the expected behavior would be different.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
slhckcommented, Nov 20, 2019

I just tried 1.0.0b5 and it works there.

0reactions
finswimmercommented, Nov 20, 2019

Thanks a lot for coming back and reporting! 👍

So I will close this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why Can't Python Find My Modules?
A common error that new Pythonistas will come across is that the packages they think they've installed are not actually being recognized by ......
Read more >
Python - package not found although it is installed
Use the Anaconda Python binary to run pip as a module; when you can run /path/to/python or pythoncommand to open the right Python...
Read more >
Installing Packages - Python Packaging User Guide - Python.org
Run python get -pip.py . 2 This will install or upgrade pip. Additionally, it will install setuptools and wheel if they're not installed...
Read more >
How to List Installed Python Packages
List Installed Packages with Anaconda Navigator · Start the Anaconda Navigator application. · Select Environments in the left column. · A dropdown ...
Read more >
How does python find packages?
I just ran into a situation where I compiled and installed Python 2.7.9 from source on Ubuntu, but Python could not find the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found