Virtualenv “. venv/bin/activate” vs “source venv/bin/activate”

前端 未结 2 1892
孤街浪徒
孤街浪徒 2020-12-31 05:32

lets say i created a virtualenv called venv (virtualenv venv)

From reading tutorials, i read there are 2 ways to activate virtual env:

  1. . venv/

相关标签:
2条回答
  • 2020-12-31 06:28

    . and source do exactly the same thing, with the only difference being that while source is more readable, it may not be available in all shells.

    The command runs the contents of the script within the current shell, and this is important in the case of activate, because one of the things that the script does is exports and modifies environment variables within your current shell.

    If you were to run it using ./path/to/activate, the script will be run within a subshell and all environment variables that are set will be lost once the script completes and the subshell terminates.

    Also for number 1, doesn't the "." just mean the current folder?

    . has a different meaning depending on the context. It only means "current folder" when used as (or part of) a path.

    From http://en.wikipedia.org/wiki/Dot_%28Unix%29:

    The dot command is not to be confused with a dot file, which is a dot-prefixed hidden file or hidden directory.


    As an aside, I would suggest that you take a look at virtualenvwrapper which provides additional wrapper commands that make virtualenv much easier to use.

    Using virtualenvwrapper, switching to an evironment is done simply by calling:

    workon YOUR_ENV
    
    0 讨论(0)
  • 2020-12-31 06:33

    The . command is essentially an alias for the source. They both execute a given script in the current shell without forking a new shell.

    Here are some nice examples.

    0 讨论(0)
提交回复
热议问题