virtualenv not working on windows cygwin - python

I have cygwin installed on a windows 7 machine. I'm trying to follow the instructions listed here:
https://www.tutorialspoint.com/flask/flask_environment.htm
Created a new project directory
cd into the new directory
Typed virtualenv venv, and it created the new virtual dir successfully
This next step fails to work for me.
I'm trying to activate the virtual env but its not working.
"venv\scripts\activate"
When i type that nothing happens.
USER#PCTEST~/newproj
$ venv/Scripts/activate
USER#PCTEST ~/newproj
$ which python
/cygdrive/c/python27/python

Solution
Run activate script with source or . (dot space) command:
source ./venv/Scripts/activate
# Or
. ./venv/Scripts/activate
Explanation
source runs shell commands in your current shell environment, so venv works as expected. While running script by name starts new isolated shell environment, activates venv there and closes new shell environment returning to original one.

Related

How can I activate my virtualenv in visual code terminal?

How can I activate my virtual environment in visual code terminal? I've tried using the workspace settings method but the settings file was empty
If you have already created your virtual environment, you can just go to its directory by running the following in the VS Code terminal:
cd /python_env/bin/
and then
source ./activate
or, you can directly run
source ./python_env/bin/activate
from your main project directory.
Please follow the steps below:
Open your project folder in VS Code
Create a new terminal
Use the following command in the terminal to create a new virtual environment
# .venv is your virtual environment name
# You can also use py -3 -m venv .venv
python -m venv .venv
After the virtual environment is generated, use the following command to activate the virtual environment
# .venv is your virtual environment name
.venv\scripts\activate
Normally, when VS Code notices that you have created a new virtual environment, a popup will prompt you to allow it to be selected for the workspace.

Powershell venv only use envirnmental variables python, not python in venv directory (Windows)

I use vevn with python 3.6.8, pip 18.1.
I set powershell executionPolicy RemoteSigned,
create virtual environment with venv, refed to venv official site : (https://docs.python.org/3.6/library/venv.html)
and also activated according to powershell, used .<venv>\Scripts\activate.ps1
But when I execute 'pip list' command, it shows all packages installed in global, not in venv.
And when execute python - import sys - sys.prefix, to check python directory,
I can find, powershell venv uses environmental variables python.
Of course, run it on cmd in same way, it works correctly.
pip list shows
The pip list shows only packages installed in venv, and sys.prefix is python in venv directory.
Does anyone know why it works like this?
Powershell works correctly like cmd
Maybe you activated the "--system-site-packages" switch by accident when installing the virtual env. This switch makes all python packages in the global system available to the virtual env.
Also check that after activating the environment your powershell indicates that you are actually using the virtual env. This is indicated by (env_name) at the beginning of the new power shell line.

How do I run a python program in a virtual environment from windows command prompt?

I created a virtual environment for a Python program using PyCharm. I can run the program just fine straight from PyCharm terminal but when I try to run it from windows command prompt I get an error because some modules in the program are only installed in the virtual environment.
So my question is: how do I run a Python program that is in a virtual environment from the command prompt?
$ cd your_project
$ ./activate.bat
$ python helloworld.py
Explaination: virtualenv should create a .bat file in your project root directory. To run it, activate the virtual env first then run the python command.
I think you have to look after switching virtual environment on windows
may be this will help
[https://towardsdatascience.com/manage-your-python-virtual-environment-with-conda-a0d2934d5195][1]

Why the virtual environment runs system Python 2.7 instead of virtual Python 3.6

I've created a Django project in a virtual environment, and venv was activated by PyCharm automatically, as usual. Everything was fine, but when I placed my project into another folder, Project Interpreter settings were corrupted because of old interpreter path.
So now, when I provide a new path for the interpreter (and, of course, with activated venv), python runs from my base system location of version 2.7, not from venv.
Check this:
archeski#archeski-Inspiron-5558:~/Source/ecom/ecom$ source venv/bin/activate
(venv) archeski#archeski-Inspiron-5558:~/Source/ecom/ecom$ python --version
Python 2.7.15rc1
(venv) archeski#archeski-Inspiron-5558:~/Source/ecom/ecom$ python -c "import sys; print sys.executable"
/usr/bin/python
The same thing happened about a half year ago on Windows 10, and the solution was only to create a project in PyCharm from scratch and then move all the source, db and etc.
Now, I'm running on Ubuntu 18.04
From https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000062344-How-to-move-complete-Python-environment-to-new-PC-with-virtual-environment
Normally environments are tied to a specific path. That means that you
cannot move an environment around or copy it to another computer. You
can fix up an environment to make it relocatable with the command:
$ virtualenv --relocatable ENV
The --relocatable option currently has a number of issues, and is not
guaranteed to work in all circumstances. It is possible that the
option will be deprecated in a future version of virtualenv

source /bin/activate activates the system interpreter not the venv one

When I run source bin/activate , the virtual environment seems to be activated since I can see (venv). However when I run which python , I realise its using the system wide interpreter i.e /usr/bin/python and therefore any modules in install are installed system wide. I created the virtual environment using Pycharm and when I my scripts through Pycharm, it works fine. But right now I need to run them through terminal and therefore I need the virtual environment.
To create virtualenv $ virtualenv env && source env/bin/activate then which python would show the right python here. You only need care while doing this. Sometimes you have to remove completely the env, close and restart the terminal and even source deactivate. Those are options. Virtualenv guide
EDIT:
There is no need to source deactivate. Deactivate is enough

Categories