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.
Related
I'm trying to use runserver command over pycharm code terminal. But now it is giving me the error. " Unable to create process using Unable to create process using 'C:\Users\ibsof\AppData\Local\Microsoft\WindowsApps\python.exe manage.py runserver'
. But I have the python interpreter in my environment path. Also, I have my virtual environment which I created while initiating the project but still and using the interpreter in my environment I was getting the same error..
This is what worked for me:
Uninstall PyCharm completely and reinstalled it.
Re-install the latest version of python via python.org
Restart your system
Ensure python path is added to your environment variable and test using command prompt("C:>python" should bring out the python version)
Open your IDE (PyCharm in my case) and re-open your project folder
Open A NEW VIRTUAL ENVIRONMENT and activate it
Re-install your dependencies ("pip install -r requirements.txt") and runserver
I actually THINK that steps 6 and 7 above is all you need, but I am just detailing what I did to make mine work.
When using Pycharm, I make my virtual environment when I m creating a new project and then never have to think about activating it or anything. It works just fine.
When I m using the terminal on my Mac OS, I need to create the virtual environment and then also activate it.
I also have to activate it for VS Code.
How do I know when I need to activate my virtual environment? Thanks.
To activate a virtual environment from the terminal, you need to source a file that the venv module created. This file typically will be in the bin directory of your project (ej. my_project/folder/bin) and will be named activate.
So to activate the environment in your shell you would run the command
source my_project/folder/bin/activate
You should know if you're already IN the virtual environment, when you see the project's name parsed to some part of your shell prompt. If you're already into your virtual environment, you can leave it with the deactivate command.
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
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
I am new to Django and new to the virtualenv scene.
I have been working on a Django project for a couple of days and completely forgot to activate my venv on my second day.
I am using this tutorial to guide me and I have been working from within my activated environment up until this point....
Is it enough to just re-run manage.py after activating my venv?
Activating a virtual environment
Before you can start installing or using packages in your virtual environment you’ll need to activate it. Activating a virtual environment will put the virtual environment-specific python and pip executables into your shell’s PATH.
On macOS and Linux:
source env/bin/activate
On Windows:
.\env\Scripts\activate
You can confirm you’re in the virtual environment by checking the location of your Python interpreter, it should point to the env directory.
On macOS and Linux:
which python
.../env/bin/python
On Windows:
where python
.../env/bin/python.exe
Leaving the virtual environment
If you want to switch projects or otherwise leave your virtual environment, simply run:
deactivate
If you want to re-enter the virtual environment just follow the same instructions above about activating a virtual environment. There’s no need to re-create the virtual environment.
For Django
After active your virtual environment you need to run Django development server. To run the Django Development server go to manage.py directory.
And run the following command:
python manage.py runserver
And your Django Development server is running at http://127.0.0.1:8000/