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.

pipenv results with "ModuleNotFoundError: No module named"; but venv works

See original GitHub issue

Hi, While trying to utilize pipenv for python package management, on OSX 10.14.6, I suspect I’ve got tangled with resolving installed site packages,

First is the output of $ pipenv --support | pbcopy -

$ pipenv --support

Pipenv version: '2018.11.26'

Pipenv location: '/usr/local/Cellar/pipenv/2018.11.26_2/libexec/lib/python3.7/site-packages/pipenv'

Python location: '/usr/local/Cellar/pipenv/2018.11.26_2/libexec/bin/python3.7'

Python installations found:

  • 3.7.4: /Users/elia/.local/share/virtualenvs/server_api-gYoqao8P/bin/python3
  • 3.7.4: /usr/local/bin/python3
  • 3.7.4: /usr/local/bin/python3.7m
  • 2.7.10: /usr/bin/python
  • 2.7.10: /usr/bin/pythonw
  • 2.7.10: /usr/bin/python2.7

PEP 508 Information:

{'implementation_name': 'cpython',
 'implementation_version': '3.7.4',
 'os_name': 'posix',
 'platform_machine': 'x86_64',
 'platform_python_implementation': 'CPython',
 'platform_release': '18.7.0',
 'platform_system': 'Darwin',
 'platform_version': 'Darwin Kernel Version 18.7.0: Thu Jun 20 18:42:21 PDT '
                     '2019; root:xnu-4903.270.47~4/RELEASE_X86_64',
 'python_full_version': '3.7.4',
 'python_version': '3.7',
 'sys_platform': 'darwin'}

System environment variables:

  • PATH
  • TERM_PROGRAM
  • SHELL
  • TERM
  • PIP_PYTHON_PATH
  • TMPDIR
  • Apple_PubSub_Socket_Render
  • TERM_PROGRAM_VERSION
  • ANDROID_SDK_ROOT
  • TERM_SESSION_ID
  • JAVA_OPTS
  • USER
  • SSH_AUTH_SOCK
  • __CF_USER_TEXT_ENCODING
  • VIRTUAL_ENV
  • TMUX
  • PIPENV_ACTIVE
  • _
  • PWD
  • JAVA_HOME
  • ITERM_PROFILE
  • TMUX_PANE
  • XPC_FLAGS
  • PYTHONDONTWRITEBYTECODE
  • XPC_SERVICE_NAME
  • COLORFGBG
  • HOME
  • SHLVL
  • ITERM_SESSION_ID
  • LOGNAME
  • PIP_DISABLE_PIP_VERSION_CHECK
  • LC_CTYPE
  • COLORTERM
  • PIP_SHIMS_BASE_MODULE
  • PYTHONFINDER_IGNORE_UNSUPPORTED

Pipenv–specific environment variables:

  • PIPENV_ACTIVE: 1

Debug–specific environment variables:

  • PATH: /usr/local/Cellar/pipenv/2018.11.26_2/libexec/tools:/Users/elia/.local/share/virtualenvs/server_api-gYoqao8P/bin:/usr/local/Cellar/pipenv/2018.11.26_2/libexec/tools:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin
  • SHELL: /bin/bash
  • PWD: /Users/elia/BE_Blog_posts/server_api
  • VIRTUAL_ENV: /Users/elia/.local/share/virtualenvs/server_api-gYoqao8P

Contents of Pipfile (‘/Users/elia/BE_Blog_posts/server_api/Pipfile’):

[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
flask = "*"

[requires]
python_version = "3.7"

Contents of Pipfile.lock (‘/Users/elia/BE_Blog_posts/server_api/Pipfile.lock’):

{
    "_meta": {
        "hash": {
            "sha256": "a82b674d67d29678775ff6b773de1686a9593749ec14483b0d8e05131b662286"
        },
        "pipfile-spec": 6,
        "requires": {
            "python_version": "3.7"
        },
        "sources": [
            {
                "name": "pypi",
                "url": "https://pypi.org/simple",
                "verify_ssl": true
            }
        ]
    },
    "default": {
        "click": {
            "hashes": [
                "sha256:2335065e6395b9e67ca716de5f7526736bfa6ceead690adf616d925bdc622b13",
                "sha256:5b94b49521f6456670fdb30cd82a4eca9412788a93fa6dd6df72c94d5a8ff2d7"
            ],
            "version": "==7.0"
        },
        "flask": {
            "hashes": [
                "sha256:13f9f196f330c7c2c5d7a5cf91af894110ca0215ac051b5844701f2bfd934d52",
                "sha256:45eb5a6fd193d6cf7e0cf5d8a5b31f83d5faae0293695626f539a823e93b13f6"
            ],
            "index": "pypi",
            "version": "==1.1.1"
        },
        "itsdangerous": {
            "hashes": [
                "sha256:321b033d07f2a4136d3ec762eac9f16a10ccd60f53c0c91af90217ace7ba1f19",
                "sha256:b12271b2047cb23eeb98c8b5622e2e5c5e9abd9784a153e9d8ef9cb4dd09d749"
            ],
            "version": "==1.1.0"
        },
        "jinja2": {
            "hashes": [
                "sha256:065c4f02ebe7f7cf559e49ee5a95fb800a9e4528727aec6f24402a5374c65013",
                "sha256:14dd6caf1527abb21f08f86c784eac40853ba93edb79552aa1e4b8aef1b61c7b"
            ],
            "version": "==2.10.1"
        },
        "markupsafe": {
            "hashes": [
                "sha256:00bc623926325b26bb9605ae9eae8a215691f33cae5df11ca5424f06f2d1f473",
                "sha256:09027a7803a62ca78792ad89403b1b7a73a01c8cb65909cd876f7fcebd79b161",
                "sha256:09c4b7f37d6c648cb13f9230d847adf22f8171b1ccc4d5682398e77f40309235",
                "sha256:1027c282dad077d0bae18be6794e6b6b8c91d58ed8a8d89a89d59693b9131db5",
                "sha256:24982cc2533820871eba85ba648cd53d8623687ff11cbb805be4ff7b4c971aff",
                "sha256:29872e92839765e546828bb7754a68c418d927cd064fd4708fab9fe9c8bb116b",
                "sha256:43a55c2930bbc139570ac2452adf3d70cdbb3cfe5912c71cdce1c2c6bbd9c5d1",
                "sha256:46c99d2de99945ec5cb54f23c8cd5689f6d7177305ebff350a58ce5f8de1669e",
                "sha256:500d4957e52ddc3351cabf489e79c91c17f6e0899158447047588650b5e69183",
                "sha256:535f6fc4d397c1563d08b88e485c3496cf5784e927af890fb3c3aac7f933ec66",
                "sha256:62fe6c95e3ec8a7fad637b7f3d372c15ec1caa01ab47926cfdf7a75b40e0eac1",
                "sha256:6dd73240d2af64df90aa7c4e7481e23825ea70af4b4922f8ede5b9e35f78a3b1",
                "sha256:717ba8fe3ae9cc0006d7c451f0bb265ee07739daf76355d06366154ee68d221e",
                "sha256:79855e1c5b8da654cf486b830bd42c06e8780cea587384cf6545b7d9ac013a0b",
                "sha256:7c1699dfe0cf8ff607dbdcc1e9b9af1755371f92a68f706051cc8c37d447c905",
                "sha256:88e5fcfb52ee7b911e8bb6d6aa2fd21fbecc674eadd44118a9cc3863f938e735",
                "sha256:8defac2f2ccd6805ebf65f5eeb132adcf2ab57aa11fdf4c0dd5169a004710e7d",
                "sha256:98c7086708b163d425c67c7a91bad6e466bb99d797aa64f965e9d25c12111a5e",
                "sha256:9add70b36c5666a2ed02b43b335fe19002ee5235efd4b8a89bfcf9005bebac0d",
                "sha256:9bf40443012702a1d2070043cb6291650a0841ece432556f784f004937f0f32c",
                "sha256:ade5e387d2ad0d7ebf59146cc00c8044acbd863725f887353a10df825fc8ae21",
                "sha256:b00c1de48212e4cc9603895652c5c410df699856a2853135b3967591e4beebc2",
                "sha256:b1282f8c00509d99fef04d8ba936b156d419be841854fe901d8ae224c59f0be5",
                "sha256:b2051432115498d3562c084a49bba65d97cf251f5a331c64a12ee7e04dacc51b",
                "sha256:ba59edeaa2fc6114428f1637ffff42da1e311e29382d81b339c1817d37ec93c6",
                "sha256:c8716a48d94b06bb3b2524c2b77e055fb313aeb4ea620c8dd03a105574ba704f",
                "sha256:cd5df75523866410809ca100dc9681e301e3c27567cf498077e8551b6d20e42f",
                "sha256:e249096428b3ae81b08327a63a485ad0878de3fb939049038579ac0ef61e17e7"
            ],
            "version": "==1.1.1"
        },
        "werkzeug": {
            "hashes": [
                "sha256:87ae4e5b5366da2347eb3116c0e6c681a0e939a33b2805e2c0cbd282664932c4",
                "sha256:a13b74dd3c45f758d4ebdb224be8f1ab8ef58b3c0ffc1783a8c7d9f4f50227e6"
            ],
            "version": "==0.15.5"
        }
    },
    "develop": {}
}

The question is how can I fix pipenv so I will be able to successfully manage packages with pipenv instead of pythons working venv

The full story -

  1. installed pipenv via brew -> as instructed in https://docs.pipenv.org/en/latest/install/#installing-pipenv
  2. The pip file contect -
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
flask = "*"
flask-cors = "*"
flask-pymongo = "*"
pymongo = "*"
bson = "*"

[requires]
python_version = "3.7"
  1. First before running pipenv install; deleting any preious using pipenv --rm and cleaning, and followed clearing cache dirs as explained in: https://docs.pipenv.org/en/latest/diagnose/#your-dependencies-could-not-be-resolved
  2. running pipenv install - finishes with no errors
Warning: the environment variable LANG is not set!
We recommend setting this in ~/.profile (or equivalent) for proper expected behavior.
Creating a virtualenv for this project…
Pipfile: /Users/elia/BE_Blog_posts/server_api/Pipfile
Using /usr/local/bin/python3 (3.7.4) to create virtualenv…
⠹ Creating virtual environment...Using base prefix '/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7'
New python executable in /Users/elia/.local/share/virtualenvs/server_api-gYoqao8P/bin/python3.7
Also creating executable in /Users/elia/.local/share/virtualenvs/server_api-gYoqao8P/bin/python
Please make sure you remove any previous custom paths from your /Users/elia/.pydistutils.cfg file.
Installing setuptools, pip, wheel...
done.
Running virtualenv with interpreter /usr/local/bin/python3

✔ Successfully created virtual environment!
Virtualenv location: /Users/elia/.local/share/virtualenvs/server_api-gYoqao8P
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
✔ Success!
Updated Pipfile.lock (6b5575)!
  🐍   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 12/12 — 00:00:02
  1. starting pipenv and attempting to run the app resolves in failure for ModuleNotFoundError: No module named 'flask'
python app.py
Traceback (most recent call last):
  File "app.py", line 1, in <module>
    from flask import Flask
ModuleNotFoundError: No module named 'flask'
  1. The Bellow is from within pipenv shell -
which python
/Users/elia/.local/share/virtualenvs/server_api-gYoqao8P/bin/python

python -m site
sys.path = [
    '/Users/elia/BE_Blog_posts/server_api',
    '/Users/elia/.local/share/virtualenvs/server_api-gYoqao8P/lib/python37.zip',
    '/Users/elia/.local/share/virtualenvs/server_api-gYoqao8P/lib/python3.7',
    '/Users/elia/.local/share/virtualenvs/server_api-gYoqao8P/lib/python3.7/lib-dynload',
    '/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7',
    '/Users/elia/.local/share/virtualenvs/server_api-gYoqao8P/lib/python3.7/site-packages',
]
USER_BASE: '/Users/elia/.local' (exists)
USER_SITE: '/Users/elia/.local/lib/python3.7/site-packages' (doesn't exist)
ENABLE_USER_SITE: False

pip list
Package          Version
---------------- ----------
bson             0.5.8
certifi          2018.10.15
Click            7.0
Flask            1.1.1
Flask-Cors       3.0.8
Flask-PyMongo    2.3.0
itsdangerous     1.1.0
Jinja2           2.10.1
MarkupSafe       1.1.1
pip              19.1.1
pipenv           2018.11.26
pymongo          3.8.0
python-dateutil  2.8.0
setuptools       41.0.1
six              1.12.0
virtualenv       16.3.0
virtualenv-clone 0.3.0
Werkzeug         0.15.5
wheel            0.33.4
  1. After not being able to resolve this lack of ability to load packages, I’ve tried the Pythons default venv following: https://opensource.com/article/19/4/managing-python-packages and after the activation of venv I’m able to successfully start the app and non modules are missing -
### output is when venv is activated (sourced activae script)
$ which python
/Users/elia/BE_Blog_posts/server_api/be_test1/bin/python

$ which pip
/Users/elia/BE_Blog_posts/server_api/be_test1/bin/pip

$ pip list
Package       Version
------------- -------
Click         7.0
Flask         1.1.1
Flask-Cors    3.0.8
Flask-PyMongo 2.3.0
itsdangerous  1.1.0
Jinja2        2.10.1
MarkupSafe    1.1.1
pip           19.2.1
pymongo       3.8.0
setuptools    40.8.0
six           1.12.0
Werkzeug      0.15.5

# python loads flask package and runs as expected - 
$ python app.py
 * Serving Flask app "app" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

I would appreciate any help with troubleshooting and fixing lovely pipenv, Thanks, Elia.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
frostmingcommented, Aug 8, 2019

np, below is a common path to solving ModuleNotFound error:

  1. Check whether the desired package is installed by pip list.
  2. Check which pip is being used.
  3. Check all possibilities to have the installation destination changed:
    • PYTHONHOME envar.
    • pip.conf
    • The old style .pydistutils.cfg
    • env|grep -i PIP
1reaction
Elia-Shcommented, Aug 8, 2019

Came back withvery good news, I’ve performed the following -

  1. removing ~/.pydistutils.cfg,
  2. pipenv --rm
  3. rm Pipfile.lock
  4. pipenv install
  5. Everythong works -
$ pipenv run python app.py
 * Serving Flask app "app" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

2 days I’ve been running pipenv --rm, delete cahce, install, completely reinstall pipenv, remove ~/.pydistutils.cfg, probably missed the above…

from within the working pipenv shell -

$ pipenv run which pip
/Users/elia/.local/share/virtualenvs/server_api-gYoqao8P/bin/pip
$  pipenv run pip --version
pip 19.2.1 from /Users/elia/.local/share/virtualenvs/server_api-gYoqao8P/lib/python3.7/site-packages/pip (python 3.7)

$  pipenv run pip list
Package         Version
--------------- -------
bson            0.5.8
Click           7.0
Flask           1.1.1
Flask-Cors      3.0.8
Flask-PyMongo   2.3.0
itsdangerous    1.1.0
Jinja2          2.10.1
MarkupSafe      1.1.1
pip             19.2.1
pymongo         3.8.0
python-dateutil 2.8.0
setuptools      41.0.1
six             1.12.0
Werkzeug        0.15.5
wheel           0.33.4

# all dependency packages installed, python loads modules and executes as expected.

Any additional info that can assist in preventing the next similar poor osx/python env/pipenv newcomer getting tangled with 101 pipenv? I’ve tried to follow the documentation instructions step by step(brew install pipenv), by somehow got into the above and could not resolve this without your help…

Again thank you very much 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

No module named 'virtualenv.seed.embed.via_app_data ...
I think virtualenv is using a different python installation that your python3 default installation, thus the ModuleNotFoundError. Easiest way to ...
Read more >
Frequently Encountered Pipenv Problems - Read the Docs
☤ No module named <module name>¶. This is usually a result of mixing Pipenv with system packages. We strongly recommend installing Pipenv in...
Read more >
pipenv Documentation - Read the Docs
Pipenv is a tool that aims to bring the best of all packaging worlds (bundler, composer, npm, cargo, yarn, etc.) to the. Python...
Read more >
No module named 'numpy'" windowsOS/pipenv shell - Python
Pipenv "ModuleNotFoundError: No module named 'numpy'" ... The fact pipenv works but python3 -m pipenv doesn't is very suggestive.
Read more >
Working with the AWS CDK in Python
If you encounter a permission error, run the above commands with the --user flag so that the modules are installed in your user...
Read more >

github_iconTop Related Medium Post

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