How to get path to virtualenv in Windows? - python

First of all, i'm using bash in windows.
I'm trying to write the correct paths to my virtualenv in VSCode but I must be doing something wrong
Any help will be really appreciated! thank you guys!
"python.pythonPath": "C\\Users\\Angel\\AppData\\Local\\Packages\\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\\LocalState\\rootfs\\home\\aquesada\\.local\\share\\virtualenvs\\videoclub_django_new-coDPKRdg\\bin\\python",
"python.linting.pylintPath": "C\\Users\\Angel\\AppData\\Local\\Packages\\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\\LocalState\\rootfs\\home\\aquesada\\.local\\share\\virtualenvs\\videoclub_django_new-coDPKRdg\\bin\\pylint",
"python.venvPath": "C:\\Users\\Angel\\AppData\\Local\\Packages\\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\\LocalState\\rootfs\\home\\aquesada\\.local\\share\\virtualenvs"

virtual env as environmental variable
A virtual environment will set an environmental variable.
In Windows, you should be able to view that variable via echo %VIRTUAL_ENV%
In your Python code, you can grab that env var via os.environ['VIRTUAL_ENV']
VS Code config
python.venvPath should work. A few more things for you to try:
adjust path formatting: a single backslash as delimiter should work; AFAIK Windows only requires two consecutive backslashes at the start of the path
restart VS Code after updating configuration
use the Command Palette to select the Python interpreter from your virtual environment

Related

Python path on windows

I have two installations of Python on a corporate Windows computer. One from the Anaconda distribution:
C:\Users\Me\AppData\Local\Continuum\anaconda3\python3.exe
Another one from a corporate installer:
C:\Users\Me\AppData\Local\Downloaded Apps\WinPython\python-3.4.3\python.exe
If I type "python" in the default "cmd" terminal or in the Git Bash, it says "command not found". Probably for the same reason, Jupyter does not allow me to create a Python 3 notebook. How do I set the paths so that Python is available system-wide? I prefer the Anaconda distribution's Python.
EDIT: Creating a new user variable PYTHONPATH and setting it to C:\Users\Me\AppData\Local\Continuum\anaconda3\ via Windows System Properties does not have an effect.
This answer describes step-by-step an approach that worked for me. However, as eryksun notes in the comment, the additional variable should not be named PYTHONPATH. I renamed it PYTHON, which works.
Strangely, adding the paths directly to the PATH variable did NOT work.
You have to add the path of your installation to the Environment variables.
Simply go to the System Properties / Environment Variables /
From there, create a new system variables and add your python path.
In the system variable section select the Path variable.
Add new variable C:\Users\Me\AppData\Local\Continuum\anaconda3\ as environment variable in your advanced System Settings.
This is from where your system will invoke the python interpreter.
For more details see this answer

In Eclipse I can't get environment variable

Ubunto 14.04
I'd like to keep secret info (passwords etc.) in environment variables of Ubuntu. I placed them in user's variables.
/home/michael/.bashrc
export SECRET_KEY=nh9_j12rx4j_zqiw235_klvm183p5g8bz_s2_fl3auc # Django
In terminal I check:
michael#michael:~$ echo $SECRET_KEY
nh9_j12rx4j_zqiw235_klvm183p5g8bz_s2_fl3auc
In python run under michael:
>>> os.environ['SECRET_KEY']
'nh9_j12rx4j_zqiw235_klvm183p5g8bz_s2_fl3auc'
Now I run Eclipse IDE and try to get os.environ['SECRET_KEY']. Well, no such environment variable. I think, maybe Eclipse can't access michael's variables even if michael started Eclipse.
Could you help me cope with this problem?
Since eclipse does not read your .bashrc, I guess you should specify your environment variables in the context menu where you can set the default interpreter.
Go to Run -> Run Configurations... and Select tab "Environment".
Otherwise, if you want those environment variables available in Eclipse you need to put them in /etc/environment.
You may consider using profile file or bash_profile to store the environment variables. You can refer more here
Another approach would be to start Eclipse from an open terminal window where you can access the respective environment variable and Eclipse should see them.

How can I set environment variable WORKON_HOME for virtualenvwrapper-win

I am trying to setup virtualenvwrapper-win on a usb drive as part of a python development environment. In https://github.com/davidmarble/virtualenvwrapper-win it states:
Optional: Add an environment variable WORKON_HOME to specify the path to store environments. By default, this is %USERPROFILE%\Envs.
but doesn't explain how to do this. Could someone help with this?
My system python is at:
/f/python27/python
AS lguananut said, you are asking how to set an environment variable.
Take Win7 as example,
execute command "sysdm.cpl"
Go to Advanced tab, open "Enviroment Variables..."
New a system variable
In pop window, set variable name = WORKON_HOME, value = [your virtual environments root]
relaunch one command prompt, all commands like mkvirtualenv, workon will works.
If you prefer Powershell like me, you could also try the following code.
[Environment]::SetEnvironmentVariable("WORKON_HOME", "C:\Venv", "User")
[Environment]::SetEnvironmentVariable("PROJECT_HOME", "C:\Project", "User")
It will create two environment variables for your current user:
WORKON_HOME
PROJECT_HOME
Paste the sample code in PowerShell window:
[Environment]::SetEnvironmentVariable("WORKON_HOME", "<Your-Virtual-Environment-Root>", "User")
[Environment]::SetEnvironmentVariable("PROJECT_HOME", "<Your-Project-Root>", "User")
It will populate the variables like
Hope it helps.

/bin/env: python: No such file or directory (Windows through Git Bash trying to install new Parse Cloud Code)

Trying to install python from the link here does not seem to give access to the python command in Msysgit... following the instructions here, does not actually say how to get python to work as needed.
Current error when running parse new project_name is:
/bin/env: python: No such file or directory
I believe it's likely because it installed it at C:\Python... anyone know how to fix this?
This error means that Git Bash does not know where your python.exe is. It searches your normal windows search path, the PATH environment variable. You're probably failing the 4th step on the instructions already "Make sure Python is working in the Git Bash":
$ python --version
sh.exe: python: command not found
To fix that, append C:\Python (or wherever you installed python) to your PATH environment variable in windows (instructions here). You need to restart the bash after this for the change to take effect. This will allow you to run python from the windows command prompt as well.
C:\> python --version
Python 2.7.2
If you don't want to alter your windows PATH variable or make python only available to git bash, you could create a .bashrc file in your %USERPROFILE% directory and set the variable there:
C:\>notepad %USERPROFILE%\.bashrc
and add
export PATH=/c/Python:$PATH
to the file. That script is executed every time you start the git bash and prepends C:\Python to git bash's PATH variable, leaving the system-wide PATH variable untouched.
Now that you know what has to be done, you can use this shortcut on the bash instead (appends the export command to your .bashrc)
$ echo export PATH=/c/Python:\$PATH >> ~/.bashrc
Hmmm. If you're using Python 2.7 like the instructions say to, you could try instead of that doing "C:/Python27/python.exe" insted of "python".
I think you can add the location of the python.exe in the PATH environment variable. Follow the steps: Go to My Computer->Right click->Properties->Advanced System Settings->Click Environmental Variables. Now click PATH and then click EDIT. In the variable value field, go to the end and append ';' (without quotes) and then add the absolute path of the .exe file which you want to run via Git-Bash.
don't know if this could be your issue, but its always worth a check.
check your python path is set correctly?
computer->properties->advanced system settings-> environment variables->system variables->PYTHONPATH, value = C:\PYTHON20;C:\PYTHON20\DLLS;C:\PYTHON20\LIB;C:\PY THON20\LIB\LIB-TK

Python Windows: correct virtualenv paths

I'm new to virtualenv and not sure how to set up paths. My paths have been set to something like this:
PYTHONPATH=C:\Python27\
PYTHONSTARTUP=C:\Python27\Scripts\startup.py
PATH=%PYTHONPATH%;...;%PYTHONPATH%\Scripts
Should I remove those paths for virtualenv's activate script to work correctly? If I can keep my paths then how do I call scripts for an env when it has been activated? Do I call scripts by explicitly running them with python.exe instead of simply typing the script name alone?
python myscript.py
Not sure how to handle the paths and I would appreciate a little guidance.
First, you have your paths wrong. PYTHONPATH tells Python in what folders to look for Python modules and normally you don't put Python's installation folder in it. For keeping installation folder of Python there's different environment variable called PYTHONHOME. So instead of PYTHONPATH=C:\Python27\ you should have PYTHONHOME=C:\Python27\. You should change PATH variable to use PYTHONHOME accordingly.
As to how to set environment variables when working with virtualenv; you don't need to do anything because virtualenv stores original values when it's activated, modifies environment variables it needs to modify and then restores original values when it's deactivated.
You can take a look at Using Python on Windows
Think you are fine just get on with virtual-env, (follow docs) but remember you must use cmd shell (NO POINT AND CLICKING!!) Took me a while before I realized that...
Once you have activated And installed what you want to in the virtual env,, you invoke scripts by "python scriptname"

Categories

Resources