Reputation: 83
I have a virtual environment and I do not know where should I save my Python file ? it only works when I run it in /home/jojo/Enviroment/venv1
can I save it in other place ? Especially when I want to use PyCharm thank you
Upvotes: 0
Views: 1154
Reputation: 13116
virtualenv and your code base can very well be in different locations. I prefer things this way. Here are sample commands that I use.
Step 1: Activate the virtualenv.
[mayank@demo /dev]$ source /usr/local/pyenv3.4/bin/activate
(pyenv3.4)[mayank@demo dev]$
Notice the prefix "(pyenv3.4)" that indicates that virtualenv is now activated.
Step 2: Ensure that python executable in virtualenv is indeed pointed by "python"
(pyenv3.4)[mayank@demo dev]$ which python
/usr/local/pyenv3.4/bin/python
Notice that python is indeed pointing to the one in virtualenv directory.
Step 3: Create a file elsewhere and execute it
echo "import sys; print(sys.executable)" > /tmp/print_python_exe.py
python /tmp/print_python_exe.py
Edit: As suggested by Paul, one might choose to keep the virtualenv directory inside the app directory. This style of structuring projects is also suggested here: http://docs.python-guide.org/en/latest/dev/virtualenvs/#basic-usage
Upvotes: 1