I have a Debian system currently running with python 2.5.4. I got virtualenv properly installed, everything is working fine. Is there a possibility that I can use a virtuale
Here is the stepbystep how to create the Virtual environment in Visual Studio Code folder:
I used Powershell (Administrator mode):
1. I create a VSCode folder - "D:\Code_Python_VE" where I want to create Virtual environment.
2. Next I type the command - "pip3 install virtualenv". (D:\Code_Python_VE> pip3 install virtualenv)
3. D:\Code_Python_VE> python3 -m venv project_env
4. D:\Code_Python_VE>project_env\Scripts\activate.bat
5. D:\Code_Python_VE> ls - This will list a new directory "project_env".
6. D:\Code_Python_VE> code . This will start Visual Studio Code. Make sure the command is (code .).
7. Create launch.jason with following content:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "python",
"request": "launch",
"name": "Python: Current File (Integrated Terminal 1)",
"program": "${file}"
},
{
"name": "Python: Current File (Integrated Terminal 2)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
(Please search how to go to Debug window and Add new Configuration in VS Code).
For Debian (debian 9) Systems in 2019, I discovered a simple solution that may solve the problem from within the virtual environment.
Suppose the virtual environment were created via:
python3.7 -m venv myenv
but only has versions of python2
and python2.7
, and you need the recent features of python3.7.
Then, simply running the command:
(myvenv) $ python3.7 -m venv --upgrade /home/username/path/to/myvenv/
will add python3.7 packages if they are already available on your system.
virtualenv --python=/usr/bin/python2.6 <path/to/myvirtualenv>
You can call virtualenv
with python version you want. For example:
python3 -m virtualenv venv
Or alternatively directly point to your virtualenv path. e.g. for windows:
c:\Python34\Scripts\virtualenv.exe venv
And by running:
venv/bin/python
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 5 2015, 21:12:44)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
you can see the python version installed in virtual environment
For Mac(High Sierra), install the virtualenv on python3 and create a virtualenv for python2:
$ python3 -m pip install virtualenv
$ python3 -m virtualenv --python=python2 vp27
$ source vp27/bin/activate
(vp27)$ python --version
Python 2.7.14
Even easier, by using command substitution to find python2 for you:
virtualenv -p $(which python2) <path/to/new/virtualenv/>
Or when using virtualenvwrapper :
mkvirtualenv -p $(which python2) <env_name>