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.

Django commands work with `pipenv run`, but not in `pipenv shell` activated environment

See original GitHub issue

I believe this is a unique concern after checking through open issues and reviewing the diagnose documentation, including the No module named <module name> section.

I have pipenv 2018.7.1 (latest) installed according to the Pragmatic Installation of Pipenv instructions in a debian/contrib-stretch64 Vagrant VM running Python 3.7 (same issue in 3.6 as well). Django version 2.0.7 (latest) is installed with pipenv.

Issue description

I am able to run Django commands using pipenv run python manage.py ..., but with pipenv shell a ModuleNotFoundError exception is thrown.

Expected result

pipenv run <command> and pipenv shell + <command> should produce the same result.

$ pipenv run python manage.py check
System check identified no issues (0 silenced).        
$ pipenv shell
(vagrant) $ python manage.py check
System check identified no issues (0 silenced).        
Actual result

pipenv run <command> works as expected but pipenv shell + <command> produces ModuleNotFoundError

$ pipenv run python manage.py check                                              
Loading .env environment variables...                                                                                                                                                                               
System check identified no issues (0 silenced).                                                                  
$ pipenv shell                                                                   
Loading .env environment variables...                                                                            
Launching subshell in virtual environment…                                                                       
$  . /vagrant/.venv/bin/activate                                                 
(vagrant) $ python manage.py check                                                
Traceback (most recent call last):                                                                               
  File "manage.py", line 8, in <module>                                                                          
    from django.core.management import execute_from_command_line                                                 
ModuleNotFoundError: No module named 'django'                                                                    
                                                                                                                 
The above exception was the direct cause of the following exception:                                             
                                                                                                                 
Traceback (most recent call last):                                                                               
  File "manage.py", line 14, in <module>                                                                         
    ) from exc                                                                                                   
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment var
iable? Did you forget to activate a virtual environment?                                                         
Steps to replicate
$ python3 -m pip install --user pipenv
$ cd myproject
$ pipenv install django
$ pipenv shell 
(myproject-gKDsaKU3) $ python manage.py check

$ pipenv --support

Pipenv version: '2018.7.1'

Pipenv location: '/home/vagrant/.local/lib/python3.7/site-packages/pipenv'

Python location: '/usr/bin/python3.7'

Other Python installations in PATH:

  • 2.7: /usr/bin/python2.7

  • 2.7: /usr/bin/python2.7

  • 3.6: /usr/bin/python3.6m

  • 3.6: /usr/bin/python3.6

  • 3.7: /usr/bin/python3.7m

  • 3.7: /usr/bin/python3.7

  • 2.7.15: /usr/bin/python

  • 2.7.15: /usr/bin/python2

  • 3.6.6: /usr/bin/python3

PEP 508 Information:

{'implementation_name': 'cpython',
 'implementation_version': '3.7.0',
 'os_name': 'posix',
 'platform_machine': 'x86_64',
 'platform_python_implementation': 'CPython',
 'platform_release': '4.9.0-6-amd64',
 'platform_system': 'Linux',
 'platform_version': '#1 SMP Debian 4.9.88-1+deb9u1 (2018-05-07)',
 'python_full_version': '3.7.0',
 'python_version': '3.7',
 'sys_platform': 'linux'}

System environment variables:

  • LS_COLORS
  • ALLOWED_HOSTS
  • PROJECT_NAME
  • SSH_CONNECTION
  • LANG
  • OLDPWD
  • DEBUG
  • SECRET_KEY
  • XDG_SESSION_ID
  • USER
  • PIP_PYTHON_PATH
  • PWD
  • HOME
  • SSH_CLIENT
  • POSTGRES_PORT
  • POSTGRES_DB
  • PIPENV_ACTIVE
  • SSH_TTY
  • MAIL
  • EMAIL_HOST_USER
  • SHELL
  • TERM
  • POSTGRES_PASSWORD
  • EMAIL_HOST
  • POSTGRES_USER
  • PYTHONDONTWRITEBYTECODE
  • SHLVL
  • LOGNAME
  • XDG_RUNTIME_DIR
  • EMAIL_PORT
  • PATH
  • PS1
  • POSTGRES_HOST
  • EMAIL_HOST_PASSWORD
  • _

Pipenv–specific environment variables:

  • PIPENV_ACTIVE: 1

Debug–specific environment variables:

  • PATH: /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/vagrant/.local/bin:/home/vagrant/.local/bin
  • SHELL: /bin/bash
  • LANG: en_US.UTF-8
  • PWD: /vagrant

Contents of Pipfile (‘/vagrant/Pipfile’):

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

[packages]
django = "*"
"psycopg2" = "*"

[dev-packages]

[requires]
python_version = "3.7"

Contents of Pipfile.lock (‘/vagrant/Pipfile.lock’):

{
    "_meta": {
        "hash": {
            "sha256": "0350b2d3dd5c14854a848f6456f7d0a4f0079a4b2a6a3b79bf68366faa70c6eb"
        },
        "pipfile-spec": 6,
        "requires": {
            "python_version": "3.7"
        },
        "sources": [
            {
                "name": "pypi",
                "url": "https://pypi.org/simple",
                "verify_ssl": true
            }
        ]
    },
    "default": {
        "django": {
            "hashes": [
                "sha256:97886b8a13bbc33bfeba2ff133035d3eca014e2309dff2b6da0bdfc0b8656613",
                "sha256:e900b73beee8977c7b887d90c6c57d68af10066b9dac898e1eaf0f82313de334"
            ],
            "index": "pypi",
            "version": "==2.0.7"
        },
        "psycopg2": {
            "hashes": [
                "sha256:0b9e48a1c1505699a64ac58815ca99104aacace8321e455072cee4f7fe7b2698",
                "sha256:0f4c784e1b5a320efb434c66a50b8dd7e30a7dc047e8f45c0a8d2694bfe72781",
                "sha256:0fdbaa32c9eb09ef09d425dc154628fca6fa69d2f7c1a33f889abb7e0efb3909",
                "sha256:11fbf688d5c953c0a5ba625cc42dea9aeb2321942c7c5ed9341a68f865dc8cb1",
                "sha256:19eaac4eb25ab078bd0f28304a0cb08702d120caadfe76bb1e6846ed1f68635e",
                "sha256:3232ec1a3bf4dba97fbf9b03ce12e4b6c1d01ea3c85773903a67ced725728232",
                "sha256:36f8f9c216fcca048006f6dd60e4d3e6f406afde26cfb99e063f137070139eaf",
                "sha256:59c1a0e4f9abe970062ed35d0720935197800a7ef7a62b3a9e3a70588d9ca40b",
                "sha256:6506c5ff88750948c28d41852c09c5d2a49f51f28c6d90cbf1b6808e18c64e88",
                "sha256:6bc3e68ee16f571681b8c0b6d5c0a77bef3c589012352b3f0cf5520e674e9d01",
                "sha256:6dbbd7aabbc861eec6b910522534894d9dbb507d5819bc982032c3ea2e974f51",
                "sha256:6e737915de826650d1a5f7ff4ac6cf888a26f021a647390ca7bafdba0e85462b",
                "sha256:6ed9b2cfe85abc720e8943c1808eeffd41daa73e18b7c1e1a228b0b91f768ccc",
                "sha256:711ec617ba453fdfc66616db2520db3a6d9a891e3bf62ef9aba4c95bb4e61230",
                "sha256:844dacdf7530c5c612718cf12bc001f59b2d9329d35b495f1ff25045161aa6af",
                "sha256:86b52e146da13c896e50c5a3341a9448151f1092b1a4153e425d1e8b62fec508",
                "sha256:985c06c2a0f227131733ae58d6a541a5bc8b665e7305494782bebdb74202b793",
                "sha256:a86dfe45f4f9c55b1a2312ff20a59b30da8d39c0e8821d00018372a2a177098f",
                "sha256:aa3cd07f7f7e3183b63d48300666f920828a9dbd7d7ec53d450df2c4953687a9",
                "sha256:b1964ed645ef8317806d615d9ff006c0dadc09dfc54b99ae67f9ba7a1ec9d5d2",
                "sha256:b2abbff9e4141484bb89b96eb8eae186d77bc6d5ffbec6b01783ee5c3c467351",
                "sha256:cc33c3a90492e21713260095f02b12bee02b8d1f2c03a221d763ce04fa90e2e9",
                "sha256:d7de3bf0986d777807611c36e809b77a13bf1888f5c8db0ebf24b47a52d10726",
                "sha256:db5e3c52576cc5b93a959a03ccc3b02cb8f0af1fbbdc80645f7a215f0b864f3a",
                "sha256:e168aa795ffbb11379c942cf95bf813c7db9aa55538eb61de8c6815e092416f5",
                "sha256:e9ca911f8e2d3117e5241d5fa9aaa991cb22fb0792627eeada47425d706b5ec8",
                "sha256:eccf962d41ca46e6326b97c8fe0a6687b58dfc1a5f6540ed071ff1474cea749e",
                "sha256:efa19deae6b9e504a74347fe5e25c2cb9343766c489c2ae921b05f37338b18d1",
                "sha256:f4b0460a21f784abe17b496f66e74157a6c36116fa86da8bf6aa028b9e8ad5fe",
                "sha256:f93d508ca64d924d478fb11e272e09524698f0c581d9032e68958cfbdd41faef"
            ],
            "index": "pypi",
            "version": "==2.7.5"
        },
        "pytz": {
            "hashes": [
                "sha256:a061aa0a9e06881eb8b3b2b43f05b9439d6583c206d0a6c340ff72a7b6669053",
                "sha256:ffb9ef1de172603304d9d2819af6f5ece76f2e85ec10692a524dd876e72bf277"
            ],
            "version": "==2018.5"
        }
    },
    "develop": {}
}

Issue Analytics

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

github_iconTop GitHub Comments

8reactions
lorenzorapetticommented, Jul 17, 2020

For anyone stumbling upon this issue, i got this exact error because I was aliasing python to python3 and pip to pip3. Removing the aliases did it for me.

0reactions
nicholasjhscommented, Jan 19, 2021

For anyone stumbling upon this issue, i got this exact error because I was aliasing python to python3 and pip to pip3. Removing the aliases did it for me.

Yes ! This worked for me too (I had an alias to another python thing). Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pipenv doesn't recognize virtual environment that was created ...
I'm using python 3.9 and installed pipenv using python3 -m pip install pipenv . I have a project with a requirements.txt and after...
Read more >
Why Use Pipenv to Create a Python Environment? - MakeUseOf
Pipenv combines Pip and Virtualvenv; you no longer use them separately. ... Run the pipenv shell command to enter the Pipenv virtual ...
Read more >
Advanced Usage of Pipenv - Read the Docs
This document covers some of Pipenv's more glorious and advanced features. ... virtual environment even if you have not activated the pipenv shell...
Read more >
Set up a Basic Django Project with Pipenv
To install pipenv , open a terminal window and run the following command: ... we need for a new virtual environment but we...
Read more >
Configure a Pipenv environment | PyCharm Documentation
Install Pipenv · Run the following command: $ py -m site --user-site. A sample output can be: · Replace site-packages with Scripts in...
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