pipenv run with Bash builtin does not respect .env

Created on 16 Jul 2018  Â·  2Comments  Â·  Source: pypa/pipenv

Issue description

pipenv run with .env set does not respect the set environment, but uses the outside environment instead. This does not happen with regular executables.

Steps to replicate
$ ls -a
.            ..           Pipfile      Pipfile.lock
$ export HELLO=WORLD
$ pipenv run echo $HELLO     # Works as intended.
WORLD
$ unset HELLO
$ echo 'HELLO=WORLD' > .env
$ pipenv run echo $HELLO    # This does not work.
Loading .env environment variables…


$ pipenv run python -c 'import os; print(os.environ["HELLO"])'   # But this does!
Loading .env environment variables…
WORLD
$ pipenv run /usr/local/bin/python3 -c 'import os; print(os.environ["HELLO"])'   # This works too.
Loading .env environment variables…
WORLD
Expected result

Both builtin and real executables should reflect .env.

Actual result

Only real executables do. Builtins don’t.


$ pipenv --support

Pipenv version: '2018.7.1'

Pipenv location: '/Users/uranusjr/Documents/programming/python/pipenv/pipenv/pipenv'

Python location: '/Users/uranusjr/.local/venvs/pipenv/bin/python'

Other Python installations in PATH:

  • 2.7: /Users/uranusjr/Library/PythonUp/cmd/python2.7
  • 2.7: /Users/uranusjr/Library/PythonUp/cmd/python2.7
  • 2.7: /usr/local/bin/python2.7
  • 2.7: /usr/bin/python2.7
  • 3.4: /Users/uranusjr/Library/PythonUp/cmd/python3.4
  • 3.4: /Users/uranusjr/Library/PythonUp/cmd/python3.4
  • 3.5: /Users/uranusjr/Library/PythonUp/cmd/python3.5
  • 3.5: /Users/uranusjr/Library/PythonUp/cmd/python3.5
  • 3.6: /Users/uranusjr/Library/PythonUp/cmd/python3.6
  • 3.6: /Users/uranusjr/Library/PythonUp/cmd/python3.6
  • 3.7: /Users/uranusjr/Library/PythonUp/bin/python3.7m
  • 3.7: /Users/uranusjr/Library/PythonUp/cmd/python3.7
  • 3.7: /usr/local/bin/python3.7

  • 2.7.15: /usr/local/bin/python

  • 2.7.10: /usr/bin/python
  • 2.7.15: /Users/uranusjr/Library/PythonUp/bin/python2
  • 2.7.15: /usr/local/bin/python2
  • 3.7.0: /Users/uranusjr/Library/PythonUp/bin/python3
  • 3.7.0: /usr/local/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': '17.7.0',
 'platform_system': 'Darwin',
 'platform_version': 'Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT '
                     '2018; root:xnu-4570.71.2~1/RELEASE_X86_64',
 'python_full_version': '3.7.0',
 'python_version': '3.7',
 'sys_platform': 'darwin'}

System environment variables:

  • PIPENV_VENV_IN_PROJECT
  • LC_ALL
  • HOMEBREW_NO_AUTO_UPDATE
  • ANDROID_HOME
  • LANG
  • XPC_FLAGS
  • DISPLAY
  • OLDPWD
  • TERM_SESSION_ID
  • WORKON_HOME
  • EDITOR
  • PIPENV_SHELL_FANCY
  • SSH_AUTH_SOCK
  • USER
  • AUTOENV_ENV_FILENAME
  • LSCOLORS
  • VIRTUALENVWRAPPER_VIRTUALENV
  • RBENV_SHELL
  • PWD
  • HOME
  • TERM_PROGRAM
  • CLICOLOR
  • TERM_PROGRAM_VERSION
  • PGDATA
  • Apple_PubSub_Socket_Render
  • TMPDIR
  • PIP_REQUIRE_VIRTUALENV
  • VIRTUALENVWRAPPER_PYTHON
  • XPC_SERVICE_NAME
  • TERM
  • SHELL
  • SECURITYSESSIONID
  • SHLVL
  • LOGNAME
  • CUTESHOP_EXTRA_SPEC_SOURCES
  • PATH
  • PS1
  • DOCKERVM
  • PIPENV_TIMEOUT
  • HOMEBREW_GITHUB_API_TOKEN
  • _
  • __CF_USER_TEXT_ENCODING
  • PYTHONDONTWRITEBYTECODE
  • PIP_PYTHON_PATH

Pipenv–specific environment variables:

  • PIPENV_VENV_IN_PROJECT: 1
  • PIPENV_SHELL_FANCY: 1
  • PIPENV_TIMEOUT: 60

Debug–specific environment variables:

  • PATH: /Users/uranusjr/.local/bin:/Users/uranusjr/.cargo/bin:/Users/uranusjr/.rbenv/shims:/Users/uranusjr/Library/PythonUp/bin:/Users/uranusjr/Library/PythonUp/cmd:/usr/local/sbin:/Users/uranusjr/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/TeX/texbin
  • SHELL: /usr/local/bin/bash
  • EDITOR: vim
  • LANG: en_US.UTF-8
  • PWD: /Users/uranusjr/Documents/play/pipenv-try

Contents of Pipfile ('/Users/uranusjr/Documents/play/pipenv-try/Pipfile'):

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

[packages]
azure-cosmosdb-table = "*"

[dev-packages]

[requires]
python_version = "3.7"

Contents of Pipfile.lock ('/Users/uranusjr/Documents/play/pipenv-try/Pipfile.lock'):

{
    "_meta": {
        "hash": {
            "sha256": "00e1682f0c272b5158e801715c9e727145e67ce60c7942f8e3cf8002e3a46299"
        },
        "pipfile-spec": 6,
        "requires": {
            "python_version": "3.7"
        },
        "sources": [
            {
                "name": "pypi",
                "url": "https://pypi.org/simple",
                "verify_ssl": true
            }
        ]
    },
    "default": {
        "asn1crypto": {
            "hashes": [
                "sha256:2f1adbb7546ed199e3c90ef23ec95c5cf3585bac7d11fb7eb562a3fe89c64e87",
                "sha256:9d5c20441baf0cb60a4ac34cc447c6c189024b6b4c6cd7877034f4965c464e49"
            ],
            "version": "==0.24.0"
        },
        "azure-common": {
            "hashes": [
                "sha256:b087e80e8f0adc858f0a2b9ba596bb791383f74834b4acc4b47b64ddfa1362e3",
                "sha256:ff0c70b1f024fed34e94302fadada9a613d0d3312547eb738b1d24af356acec7"
            ],
            "version": "==1.1.13"
        },
        "azure-cosmosdb-nspkg": {
            "hashes": [
                "sha256:5d83961922812ffb6e23f7321550b2916abbd7480ec5b4a798417c4a682ff5e9",
                "sha256:acf691e692818d9a65c653c7a3485eb8e35c0bdc496bba652e5ea3905ba09cd8"
            ],
            "version": "==2.0.2"
        },
        "azure-cosmosdb-table": {
            "hashes": [
                "sha256:4ea9a5464854ce0b2d44c01cb24e5c498a07d9f431878295d5d4e5d1d9e08422",
                "sha256:661a3b941944e4716f674ab6355ec5a33e69a999ddf321ce6d3becfd7186878b"
            ],
            "index": "pypi",
            "version": "==1.0.4"
        },
        "azure-nspkg": {
            "hashes": [
                "sha256:4bd758e649f57cc188db4f3c64becaca16195e057e4362b6caad56fe1e7934e9",
                "sha256:fe19ee5d8c66ee8ef62557fc7310f59cffb7230f0a94701eef79f6e3191fdc7b"
            ],
            "version": "==2.0.0"
        },
        "azure-storage-common": {
            "hashes": [
                "sha256:585658ebc784e843a285732a69aa69ef922e17c3063460c2c7b27c89f377004c",
                "sha256:a412a78618e82bf99030ce56f1f2d5fc6c2c2eec7ee1beda86ce6ea5f2c9196b"
            ],
            "version": "==1.3.0"
        },
        "azure-storage-nspkg": {
            "hashes": [
                "sha256:4fc4685aef941eab2f7fb53824254cca2e38f2a1bf33cda0c8ae654fe15827d6",
                "sha256:855315c038c0e695868025127e1b3057a1f984af9ccfbaeac4fbfd6c5dd3b466"
            ],
            "version": "==3.0.0"
        },
        "certifi": {
            "hashes": [
                "sha256:13e698f54293db9f89122b0581843a782ad0934a4fe0172d2a980ba77fc61bb7",
                "sha256:9fa520c1bacfb634fa7af20a76bcbd3d5fb390481724c597da32c719a7dca4b0"
            ],
            "version": "==2018.4.16"
        },
        "cffi": {
            "hashes": [
                "sha256:151b7eefd035c56b2b2e1eb9963c90c6302dc15fbd8c1c0a83a163ff2c7d7743",
                "sha256:1553d1e99f035ace1c0544050622b7bc963374a00c467edafac50ad7bd276aef",
                "sha256:1b0493c091a1898f1136e3f4f991a784437fac3673780ff9de3bcf46c80b6b50",
                "sha256:2ba8a45822b7aee805ab49abfe7eec16b90587f7f26df20c71dd89e45a97076f",
                "sha256:3bb6bd7266598f318063e584378b8e27c67de998a43362e8fce664c54ee52d30",
                "sha256:3c85641778460581c42924384f5e68076d724ceac0f267d66c757f7535069c93",
                "sha256:3eb6434197633b7748cea30bf0ba9f66727cdce45117a712b29a443943733257",
                "sha256:495c5c2d43bf6cebe0178eb3e88f9c4aa48d8934aa6e3cddb865c058da76756b",
                "sha256:4c91af6e967c2015729d3e69c2e51d92f9898c330d6a851bf8f121236f3defd3",
                "sha256:57b2533356cb2d8fac1555815929f7f5f14d68ac77b085d2326b571310f34f6e",
                "sha256:770f3782b31f50b68627e22f91cb182c48c47c02eb405fd689472aa7b7aa16dc",
                "sha256:79f9b6f7c46ae1f8ded75f68cf8ad50e5729ed4d590c74840471fc2823457d04",
                "sha256:7a33145e04d44ce95bcd71e522b478d282ad0eafaf34fe1ec5bbd73e662f22b6",
                "sha256:857959354ae3a6fa3da6651b966d13b0a8bed6bbc87a0de7b38a549db1d2a359",
                "sha256:87f37fe5130574ff76c17cab61e7d2538a16f843bb7bca8ebbc4b12de3078596",
                "sha256:95d5251e4b5ca00061f9d9f3d6fe537247e145a8524ae9fd30a2f8fbce993b5b",
                "sha256:9d1d3e63a4afdc29bd76ce6aa9d58c771cd1599fbba8cf5057e7860b203710dd",
                "sha256:a36c5c154f9d42ec176e6e620cb0dd275744aa1d804786a71ac37dc3661a5e95",
                "sha256:a6a5cb8809091ec9ac03edde9304b3ad82ad4466333432b16d78ef40e0cce0d5",
                "sha256:ae5e35a2c189d397b91034642cb0eab0e346f776ec2eb44a49a459e6615d6e2e",
                "sha256:b0f7d4a3df8f06cf49f9f121bead236e328074de6449866515cea4907bbc63d6",
                "sha256:b75110fb114fa366b29a027d0c9be3709579602ae111ff61674d28c93606acca",
                "sha256:ba5e697569f84b13640c9e193170e89c13c6244c24400fc57e88724ef610cd31",
                "sha256:be2a9b390f77fd7676d80bc3cdc4f8edb940d8c198ed2d8c0be1319018c778e1",
                "sha256:ca1bd81f40adc59011f58159e4aa6445fc585a32bb8ac9badf7a2c1aa23822f2",
                "sha256:d5d8555d9bfc3f02385c1c37e9f998e2011f0db4f90e250e5bc0c0a85a813085",
                "sha256:e55e22ac0a30023426564b1059b035973ec82186ddddbac867078435801c7801",
                "sha256:e90f17980e6ab0f3c2f3730e56d1fe9bcba1891eeea58966e89d352492cc74f4",
                "sha256:ecbb7b01409e9b782df5ded849c178a0aa7c906cf8c5a67368047daab282b184",
                "sha256:ed01918d545a38998bfa5902c7c00e0fee90e957ce036a4000a88e3fe2264917",
                "sha256:edabd457cd23a02965166026fd9bfd196f4324fe6032e866d0f3bd0301cd486f",
                "sha256:fdf1c1dc5bafc32bc5d08b054f94d659422b05aba244d6be4ddc1c72d9aa70fb"
            ],
            "markers": "platform_python_implementation != 'PyPy'",
            "version": "==1.11.5"
        },
        "chardet": {
            "hashes": [
                "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae",
                "sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691"
            ],
            "version": "==3.0.4"
        },
        "cryptography": {
            "hashes": [
                "sha256:3f3b65d5a16e6b52fba63dc860b62ca9832f51f1a2ae5083c78b6840275f12dd",
                "sha256:5251e7de0de66810833606439ca65c9b9e45da62196b0c88bfadf27740aac09f",
                "sha256:551a3abfe0c8c6833df4192a63371aa2ff43afd8f570ed345d31f251d78e7e04",
                "sha256:5cb990056b7cadcca26813311187ad751ea644712022a3976443691168781b6f",
                "sha256:60bda7f12ecb828358be53095fc9c6edda7de8f1ef571f96c00b2363643fa3cd",
                "sha256:64b5c67acc9a7c83fbb4b69166f3105a0ab722d27934fac2cb26456718eec2ba",
                "sha256:6fef51ec447fe9f8351894024e94736862900d3a9aa2961528e602eb65c92bdb",
                "sha256:77d0ad229d47a6e0272d00f6bf8ac06ce14715a9fd02c9a97f5a2869aab3ccb2",
                "sha256:808fe471b1a6b777f026f7dc7bd9a4959da4bfab64972f2bbe91e22527c1c037",
                "sha256:9b62fb4d18529c84b961efd9187fecbb48e89aa1a0f9f4161c61b7fc42a101bd",
                "sha256:9e5bed45ec6b4f828866ac6a6bedf08388ffcfa68abe9e94b34bb40977aba531",
                "sha256:9fc295bf69130a342e7a19a39d7bbeb15c0bcaabc7382ec33ef3b2b7d18d2f63",
                "sha256:abd070b5849ed64e6d349199bef955ee0ad99aefbad792f0c587f8effa681a5e",
                "sha256:ba6a774749b6e510cffc2fb98535f717e0e5fd91c7c99a61d223293df79ab351",
                "sha256:c332118647f084c983c6a3e1dba0f3bcb051f69d12baccac68db8d62d177eb8a",
                "sha256:d6f46e862ee36df81e6342c2177ba84e70f722d9dc9c6c394f9f1f434c4a5563",
                "sha256:db6013746f73bf8edd9c3d1d3f94db635b9422f503db3fc5ef105233d4c011ab",
                "sha256:f57008eaff597c69cf692c3518f6d4800f0309253bb138b526a37fe9ef0c7471",
                "sha256:f6c821ac253c19f2ad4c8691633ae1d1a17f120d5b01ea1d256d7b602bc59887"
            ],
            "version": "==2.2.2"
        },
        "futures": {
            "hashes": [
                "sha256:51ecb45f0add83c806c68e4b06106f90db260585b25ef2abfcda0bd95c0132fd",
                "sha256:c4884a65654a7c45435063e14ae85280eb1f111d94e542396717ba9828c4337f"
            ],
            "version": "==3.1.1"
        },
        "idna": {
            "hashes": [
                "sha256:156a6814fb5ac1fc6850fb002e0852d56c0c8d2531923a51032d1b70760e186e",
                "sha256:684a38a6f903c1d71d6d5fac066b58d7768af4de2b832e426ec79c30daa94a16"
            ],
            "version": "==2.7"
        },
        "pycparser": {
            "hashes": [
                "sha256:99a8ca03e29851d96616ad0404b4aad7d9ee16f25c9f9708a11faf2810f7b226"
            ],
            "version": "==2.18"
        },
        "python-dateutil": {
            "hashes": [
                "sha256:1adb80e7a782c12e52ef9a8182bebeb73f1d7e24e374397af06fb4956c8dc5c0",
                "sha256:e27001de32f627c22380a688bcc43ce83504a7bc5da472209b4c70f02829f0b8"
            ],
            "version": "==2.7.3"
        },
        "requests": {
            "hashes": [
                "sha256:63b52e3c866428a224f97cab011de738c36aec0185aa91cfacd418b5d58911d1",
                "sha256:ec22d826a36ed72a7358ff3fe56cbd4ba69dd7a6718ffd450ff0e9df7a47ce6a"
            ],
            "version": "==2.19.1"
        },
        "six": {
            "hashes": [
                "sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9",
                "sha256:832dc0e10feb1aa2c68dcc57dbb658f1c7e65b9b61af69048abc87a2db00a0eb"
            ],
            "version": "==1.11.0"
        },
        "urllib3": {
            "hashes": [
                "sha256:a68ac5e15e76e7e5dd2b8f94007233e01effe3e50e8daddf69acfd81cb686baf",
                "sha256:b5725a0bd4ba422ab0e66e89e030c806576753ea3ee08554382c14e685d117b5"
            ],
            "markers": "python_version != '3.0.*' and python_version != '3.1.*' and python_version < '4' and python_version >= '2.6' and python_version != '3.3.*' and python_version != '3.2.*'",
            "version": "==1.23"
        }
    },
    "develop": {}
}

Type good first issue

All 2 comments

Err, it’s not run, it’s the shell.

$ HELLO=WORLD echo $HELLO

$ export HELLO=WORLD
$ echo $HELLO
WORLD

This bug is closed yet still reproduces for me.
When executing pipenv shell and after python my_script.py all variables from .env are set and present but not when I execute pipenv run python my_script.py.

$ pipenv --support

Pipenv version: '2018.11.26'

Pipenv location: '/usr/local/lib/python2.7/dist-packages/pipenv'

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

Python installations found:

  • 3.7.1: /usr/bin/python3.7
  • 3.6.7: /usr/bin/python3.6
  • 3.6.7: /usr/bin/python3.6m
  • 3.7.1: /usr/bin/python3.7m
  • 2.7.15: /usr/bin/python

PEP 508 Information:

{'implementation_name': 'cpython',
 'implementation_version': '0',
 'os_name': 'posix',
 'platform_machine': 'x86_64',
 'platform_python_implementation': 'CPython',
 'platform_release': '4.18.0-15-generic',
 'platform_system': 'Linux',
 'platform_version': '#16-Ubuntu SMP Thu Feb 7 10:56:39 UTC 2019',
 'python_full_version': '2.7.15+',
 'python_version': '2.7',
 'sys_platform': 'linux2'}

System environment variables:

  • HISTFILE
  • QT4_IM_MODULE
  • SPARK_HOME
  • LESSOPEN
  • DBUS_SESSION_BUS_ADDRESS
  • TERMINAL_EMULATOR
  • XDG_SESSION_TYPE
  • QT_IM_MODULE
  • LOGNAME
  • USER
  • PATH
  • XDG_VTNR
  • HOME
  • DISPLAY
  • SSH_AGENT_PID
  • LANG
  • SDKMAN_CANDIDATES_API
  • VISUALVM_HOME
  • SHELL
  • XAUTHORITY
  • LANGUAGE
  • SESSION_MANAGER
  • XDG_DATA_DIRS
  • OWD
  • MANDATORY_PATH
  • QT_ACCESSIBILITY
  • PIPENV_VENV_IN_PROJECT
  • TERM
  • GNOME_DESKTOP_SESSION_ID
  • CLUTTER_IM_MODULE
  • WINDOWPATH
  • DESKTOP_AUTOSTART_ID
  • XMODIFIERS
  • GIO_LAUNCHED_DESKTOP_FILE_PID
  • JAVA_HOME
  • SDKMAN_CANDIDATES_DIR
  • USERNAME
  • XDG_SESSION_DESKTOP
  • GIO_LAUNCHED_DESKTOP_FILE
  • XDG_RUNTIME_DIR
  • GTK_IM_MODULE
  • APPDIR
  • SDKMAN_VERSION
  • PYTHONFINDER_IGNORE_UNSUPPORTED
  • SSH_AUTH_SOCK
  • KSCRIPT_HOME
  • GRADLE_HOME
  • SDKMAN_DIR
  • GDMSESSION
  • IM_CONFIG_PHASE
  • GNOME_SHELL_SESSION_MODE
  • PYTHONDONTWRITEBYTECODE
  • XDG_CONFIG_DIRS
  • PIP_PYTHON_PATH
  • XDG_CURRENT_DESKTOP
  • XDG_SESSION_ID
  • __INTELLIJ_COMMAND_HISTFILE__
  • _
  • GTK_MODULES
  • SDKMAN_PLATFORM
  • DESKTOP_SESSION
  • GPG_AGENT_INFO
  • LESSCLOSE
  • DEFAULTS_PATH
  • APPIMAGE
  • PIP_DISABLE_PIP_VERSION_CHECK
  • OLDPWD
  • GCC_COLORS
  • VERTX_HOME
  • SHLVL
  • PWD
  • TOOLBOX_VERSION
  • PIP_SHIMS_BASE_MODULE
  • KOTLIN_HOME
  • XDG_MENU_PREFIX
  • LS_COLORS
  • XDG_SEAT

Pipenv–specific environment variables:

  • PIPENV_VENV_IN_PROJECT: 1

Debug–specific environment variables: ommited

Was this page helpful?
0 / 5 - 0 ratings