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.

$PATH for shell and run is different

See original GitHub issue

Why is $PATH different when using pipenv shell or pipenv run?

[goern@tBook p (develop)]$ pipenv run python
Python 3.6.2 (default, Jul 17 2017, 16:44:47)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ["PATH"]
'/Users/goern/.rvm/gems/ruby-2.3.0/bin:/Users/goern/.rvm/gems/ruby-2.3.0@global/bin:/Users/goern/.rvm/rubies/ruby-2.3.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/go/bin:/usr/local/MacGPG2/bin:/usr/local/opt/go/libexec/bin:/Users/goern/.rvm/bin'
>>>
[goern@tBook piler-dev (develop)]$ pipenv shell
Launching subshell in virtual environment. Type 'exit' or 'Ctrl+D' to return.
[goern@tBook p (develop)]$ echo $PATH
/Users/goern/.local/share/virtualenvs/piler-dev-VN2jPVB_/bin:/Users/goern/.rvm/gems/ruby-2.3.0/bin:/Users/goern/.rvm/gems/ruby-2.3.0@global/bin:/Users/goern/.rvm/rubies/ruby-2.3.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/go/bin:/usr/local/MacGPG2/bin:/usr/local/opt/go/libexec/bin:/Users/goern/.rvm/bin
[goern@tBook p (develop)]$

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:32 (29 by maintainers)

github_iconTop GitHub Comments

3reactions
techalchemycommented, Sep 12, 2017

Because only one of them actually modifies your path. Pipenv is a dependency manager, when you use it it does not activate your virtualenv.

pipenv run does not touch your path, it simply uses your virtualenv to look for an executable. In this case, pipenv run python runs the python executable pipenv located in your project virtualenv.

pipenv shell however, promises a subshell with access to the environment. By nature this requires a modification to the path. As you can see yourself, that means it prepends the virtualenv bin to your path to ensure that you will look first in your virtualenv for executables.

So, why is your path different with these commands? Because only one of them modifies your path.

Is this causing you any problems?

1reaction
jacebrowningcommented, Sep 12, 2017

Tested with pipenv==6.2.7. Works great! Thanks @kennethreitz! 🎉

Read more comments on GitHub >

github_iconTop Results From Across the Web

Shell script -path and run command in one line - Stack Overflow
1 Answer 1 · You dont want to change your current path in order to execute different scripts at different paths. Solution: a....
Read more >
Path in script different than actual path - Unix Stack Exchange
Your script runs in a subshell - meaning that it was spawned by your interactive/login shell. A subshell is a shell spawned for...
Read more >
How to set your $PATH variable in Linux - Opensource.com
It's simple: They are a part of an environment variable, called $PATH, which your shell checks in order to know where to look....
Read more >
What Exactly is Your Shell PATH? - Medium
PATH works in a similar way — it's a global variable that contains a string of different paths separated by a : ....
Read more >
How to run a bash script via absolute path? - Super User
This is wrong, because name components of a pathname can't contain slashes and slashes separate name components. Understand that when we use "/" ......
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