Environment variable from .env available in `pipenv run python` but not in `pipenv shell`
See original GitHub issueI’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:
- Created 6 years ago
- Reactions:1
- Comments:6 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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:
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.
I have experienced this same problem. I suspect MacOS is treating
DYLD_LIBRARY_PATH
specially.This seems like a likely explanation:
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.)