How to install virtualenv and virtualenvwrapper properly? [duplicate] - python

Could anyone please help me with how to fix the virtuaenv issue on windows 10 - 64-bit pc. I repeatedly keep getting this error while I try to create a virtual env using windows Powershell/Command windows to install Django projects
Error message "mkvirtualenv : The term 'mkvirtualenv' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again."
Appreciate your advice

First thing first, create a new folder or directory where you want to create your virtual environment. Once done locate that folder through CMD prompt.
Now, To create virtual environment in command prompt you first need to create a virtual environment wrapper first and with the help of that you can create virtual environment. Make sure you have python in your system before following below steps, type these commands one by one in your CMD prompt:
pip install virtualenvwrapper-win
mkvirtualenv name
note: in second code you can choose any name for your virtual environment
note: You will see something like this in your CMD prompt (name) C:\Users....
now install django in this virtual environment, just type the following command
pip install django
All done !
Extras (optional)
To check django version:
django-admin --version
(Type this command in your virtual environment only)
To work again on the same virtual environment:
workon name
( In place of enter the name of your virtual environment)
To stop virtual environment:
deactivate
( Yup, only this one code)
And then exit, happy coding :)

The package which will provide "mkvirtualenv" has not been installed on your computer or your computer cannot locate where it is.
These packages below should be installed:
pip install virtualenv
pip install virtualenvwrapper-win

i also got the same problem and this how i managed to overcome it
1- specify a directory/folder where you are to store the project using cmd ie for windows
create a folder eg on desktop to store the project
C:\Users\zack>cd desktop
create a virtual environment folder on desktop using venv in the terminal
C:\Users\zack\Desktop>py -m venv django_project
activate the virtual environment using scripts\activate.bat
C:\Users\zack\Desktop>django_project\scripts\activate.bat
you will see the virtual environment project on the desktop as shown below
(django_project) C:\Users\zack\Desktop>
at the end a virtual environment folder is created on the desktop

Related

Virtualenv Issue: Django Project

I had created and activated virtualenv and worked on my Django Project.
Now scene is that i've Reinstall my Windows 10. Now when i tried to enter my env e.g. workon DFMS
I face following error...
'workon' is not recognized as an internal or external command,operable program or batch file.
Or When i tried to run server using python manage.py runserver i face following issue...
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
My Question is how to activate that old virtualenv for that project? and how to resolve this problem?
Thank You.
You could create a virtual environment with virtualenv venv and start it with venv/bin/activate.
make sure added the directory of your project into environment variable of your computer
you need to run Command prompt as Administrator.

How to make pipenv install virtual environment in project folder on Windows 10

I want to fully understand how pipenv works.
I created my project and would like virtual environment also be in same project folder.
However pipenv installs virtual environment in C:\Users\username\.virtualenvs.
With that, if I change the name or location of my project path, the virtual environment will be lost.
So how can I install virtual environment inside project folder?
I read about setting variable PIPENV_VENV_IN_PROJECT but I did not understand where and how should I do that using Powershell in windows.
Can somebody advise?
Create a .venv folder in your project root. Then run:
pipenv shell
Obviously run that from a terminal session in your project root. Pipenv should check to see if there is an empty .venv and if it finds one it should blow your virtual environment into that.
You should add PIPENV_VENV_IN_PROJECT=1 to the Windows 10 User variable
Check out this for step by step process link where I mentioned the process with images
if you can't open: https://gist.github.com/Saketh-Chandra/28ac93aca0afb8a627ef66edaf575b0d

Problems setting up a python 3.7 virtual environment

I am trying to create a new python 3.7 virtual environment on my local computer running Windows 8. I have python versions 3.6, 3.7, and 3.8 installed. Their exe's are named python36, python37, and python, respectively. All three are correctly added to PATH because I can enter each interpreter.
Within my new project's directory I tried to create a virtual environment with python37 -m venv env. It produced an error: Error: [WinError 2] The system cannot find the file specified, but it still created the directory. However the Scripts subfolder is empty except for pythonw.exe.
In this question someone suggests doing python37 -m venv env --without-pip. When I tried this, the activation/deactivation scripts were created, but the virtual environment is using python 3.8.
It is my understanding that venv will create the virtual environment with what ever python exe you use to call it, so I don't understand how this can happen. I've verified that python37 points to the correct place with where python37, and can even enter the 3.7 interactive interpreter.
The problem was that I renamed the python exe's. I don't know exactly what goes wrong, but presumably at some point venv tries to find python.exe and is thrown off by the name.
Changing them back to python.exe and differentiating between the versions with their location fixed the problem.
Edit:
Check out Eryk's comments for more details.
First create folder at any drive then go to that folder and install virtualenv package using pip.
pip install virtualenv
Then create your virtual environment.
mkvirtualenv myvirtualenv
Then use below command to activate virtualenv in windows.
myvirtualenv\Scripts\activate
After this you can install related package in current virtual environment.
The Python Standard Library for Creating Virtual Environment

How to activate virtual environment from Windows 10 command prompt

I'm trying to create and activate a virtual environment, using Windows 10 command prompt. I know that virtualenv is installed correctly, as the command
virtualenv venv
Works. I've navigated to my virtualenv download, Downloads\venv\Scripts, and am trying to activate my virtual environment venv. I've tried
venv activate
Which doesn't work since Windows doesn't recognize venv as a command. I've also tried
virtualenv venv activate
Which also doesn't work since virtualenv is saying that "venv activate" isn't a valid argument.
Use the activate script in the Scripts directory of your virtual environment:
> venv\Scripts\activate
This will activate your virtual environment and your terminal will look like this depending on the directory you're in:
(venv) C:\Users\acer\Desktop>
I hope this helps!
If you're using virtualenvwrapper-win, and using the DOS command prompt (as opposed to e.g. Powershell), then new virtualenvs are created using:
mkvirtualenv myenv
and activated using
workon myenv
You should define the environment variable WORKON_HOME to point to where you want you virtualenvs to reside.
If you've installed virtualenvwrapper-win>=1.2.4 then the virtualenvwrapper command will give you a list available commands:
go|c:\srv> virtualenvwrapper
virtualenvwrapper is a set of extensions to Ian Bicking's virtualenv
tool. The extensions include wrappers for creating and deleting
virtual environments and otherwise managing your development workflow,
making it easier to work on more than one project at a time without
introducing conflicts in their dependencies.
virtualenvwrapper-win is a port of Dough Hellman's virtualenvwrapper to Windows
batch scripts.
Commands available:
add2virtualenv: add directory to the import path
cdproject: change directory to the active project
cdsitepackages: change to the site-packages directory
cdvirtualenv: change to the $VIRTUAL_ENV directory
lssitepackages: list contents of the site-packages directory
lsvirtualenv: list virtualenvs
mkproject: create a new project directory and its associated virtualenv
mkvirtualenv: Create a new virtualenv in $WORKON_HOME
rmvirtualenv: Remove a virtualenv
setprojectdir: associate a project directory with a virtualenv
toggleglobalsitepackages: turn access to global site-packages on/off
virtualenvwrapper: show this help message
whereis: return full path to executable on path.
workon: list or change working virtualenvs
From the directory where you have your virtual environment (e.g. myenv)
you need to run the following command: .\myenv\Scripts\activate
Go to the folder where you have created the virtual environment in cmd and
enter the command .\venv\Scripts\activate
It will activate the virtual env in windows
from the command (cmd) prompt:
call venv/Scripts/activate
Make sure the Python Scripts folder is in your environment variables.
Usually the path is: "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\Scripts"
(Change "admin" to your windows username and "Python37-32" path according to your python version)
When you use "virtualenv" to create an env, it saves an "activate.bat" file in the scripts folder originating from the directory you ran the first command. E.g if you ran the command virtualenv env from C:/Users/Name/Documents/..., the .bat will be located in C:/Users/Name/Documents/.../env/scripts/activate.bat. You can run it from there.
Simply you can activate your virtualenv using command: workon myenvname
You can also create a command-line script like this -
#echo off
CD\
CD "C:\Users\[user name]\venv\Scripts"
start activate.bat
start jupyter notebook
Save this in a notepad file with an extension ".cmd".
You are ready to go
if you have anaconda installed then open anaconda terminal and type
> conda env list # for list of environment you already have
> conda activate {env_name} # to activate the environment
This works for me from Anaconda prompt,
.\\myvenv\\Scripts\\activate.bat
start python 3.7
python -m virtualenv
"You must provide a DEST_DIR"
python -m venv demodjango("demodjango is file name)"
activate.bat
pip install django
django-admin.py startproject demo1 (demo1 is my project)
python manage.py runserver
Performing system checks...
After doing this on a command prompt, you will get an URL. Click on that and you will see a message in the browser window that Django has been properly installed.

Trouble installing venv python 2.7.12

I am currently learning Flask and to do so I have to install virtualenv. It installs it normally but after that I have to activate the environment. In the tutorial it says that I have to type this into CMD:
venv\scripts\activate
It gives me the error: "The system cannot find the path specified".
I tried to run this and it doesn't work either:
venv\Scripts\activate.bat
Any help will be really appreciated.
First make sure where your working directory of your project is,lets say you have your venv in a directory called FolderX. Go to the directory's location, hold shift and right click on it then click on "Open terminal here" from the right click option.Now that you have terminal/cmd opened in that directory, type in venv\Scripts\activate.bat or venv\Scripts\activate. Do make sure that you have activate.py or activate.bat in the specific path.
You can also try this if not installed:
pip install virtualenv
If you have it installed,create another virtual environment for the project.Type these in your terminal:
cd my_project_folder
virtualenv venv
venv/bin/activate

Categories

Resources