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.

Environment variable from .env available in `pipenv run python` but not in `pipenv shell`

See original GitHub issue

I’ve run into a strange error where a environment variable declared in a .env file is available in pipenv run python but not in pipenv shell. This only happens if the variable is named DYLD_LIBRARY_PATH.

I’m using macOs High Sierra, Python 3.6.3, pipenv 8.2.6.

Setup to reproduce:

$ mkdir envtest
$ cd envtest
$ pipenv --three
Creating a virtualenv for this project…
Using /usr/local/bin/python3.6m to create virtualenv…
⠋Running virtualenv with interpreter /usr/local/bin/python3.6m
Using base prefix '/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6'
New python executable in /Users/tf/.local/share/virtualenvs/envtest-S14rkyS9/bin/python3.6
Also creating executable in /Users/tf/.local/share/virtualenvs/envtest-S14rkyS9/bin/python
Installing setuptools, pip, wheel...done.

Virtualenv location: /Users/tf/.local/share/virtualenvs/envtest-S14rkyS9
Creating a Pipfile for this project…
$ echo "DYLD_LIBRARY_PATH=Teststring" > .env
$ cat .env
DYLD_LIBRARY_PATH=Teststring

Now this works as expected:

$ pipenv run python
>>> import os; os.environ['DYLD_LIBRARY_PATH']
'Teststring'

And this does not:

$ pipenv shell
Loading .env environment variables…
Spawning environment shell (/bin/zsh). Use 'exit' to leave.
source /Users/tf/.local/share/virtualenvs/envtest-S14rkyS9/bin/activate
$ echo $DYLD_LIBRARY_PATH

$ python
>>> import os; os.environ['DYLD_LIBRARY_PATH']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/tf/.local/share/virtualenvs/envtest-S14rkyS9/bin/../lib/python3.6/os.py", line 669, in __getitem__
    raise KeyError(key) from None
KeyError: 'DYLD_LIBRARY_PATH'

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
tfeldmanncommented, Oct 19, 2017

It only affects the DYLD_LIBRARY_PATH variable.

To test I added three more variables to the .env file to check whether it has something to do with the underscores:

SOMETHING=something
SOMETHING_1=something1
SOMETHING_1_2=something2

They are fully available in $ pipenv run python and $ pipenv shell. DYLD_LIBRARY_PATH is only available in $ pipenv run python.

The variable is often needed for PySide installations.

0reactions
strazcommented, Nov 12, 2019

I have experienced this same problem. I suspect MacOS is treating DYLD_LIBRARY_PATH specially.

This seems like a likely explanation:

It turns out that this is due to a new ‘feature’ in System Integrity Protection. It will delete DYLD_* variables when launching subprocesses.

Have you tried to reproduce this on your own system with DYLD_LIBRARY_PATH? I can reproduce this on a fairly new MacOS laptop (cleanly installed Mac OS 10.14.6 with no profile or rc files.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced Usage of Pipenv - Read the Docs
Pipenv will expand environment variables (if defined) in your Pipfile. Quite useful if you need to authenticate to a private PyPI:.
Read more >
How do I set environment variables in pipenv? - Stack Overflow
env. You can run the following command from the right folder to create this .env file : echo MY_TOKEN=SuperToKen >.env # create ...
Read more >
Advanced Usage of Pipenv — pipenv 11.7.2 documentation
pipenv comes with a handful of options that can be enabled via shell environment variables. To activate them, simply create the variable in...
Read more >
Terminal not loading environmental variables with PIPENV
I have a .env file with FLASK_APP=ccadmin.py defined. The problem is that when I run flask shell in the PyCharm Terminal, it's not...
Read more >
pipenv Documentation - manpages.ubuntu!
When no parameters are passed to install, all packages [packages] specified will be installed. • To initialize a Python 3 virtual environment, run...
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