How do I activate a virtual environment in Windows 7 [duplicate] - python

This question already has answers here:
Trying to create a virtualenv in python and activate it
(3 answers)
Closed 3 years ago.
I currently need to work on a flask project, to do that, I need to activate a virtual environment for my project. Virtual environment has already been installed at Python37\Scripts folder, but each time I want to activate the virtual environment by running C:\Users\user\Desktop\flask-intro\venv\Scripts>activate. <flask-intro is my project folder>. I get an error that says 'activate' is not recognized as an internal or external command, operable program, or batch file. What could be the issue.

To Create and activate a Virtual Env for project on windows, navigate to your project directory on your command line window and run the following commands
To create - python -m venv your-env-name
To activate - your-env-name\Scripts\activate.bat

You don't need to provide full path to the script, it's enough to use like this: \path\to\env\Scripts\activate and it should be activated.
Also you can check this page for more details about it: https://virtualenv.pypa.io/en/latest/userguide/#activate-script

Related

Can't activate python virtual environment [duplicate]

This question already has answers here:
'virtualenv' won't activate on Windows
(23 answers)
Closed last month.
I'm new to python and have been learning how to use a virtual environment.
I followed the tutorial on youtube and created a virtual environment using this command:
python -m venv venv-testing
and tried to activate it using this command:
venv-testing\Scripts\activate.bat
I expected there was my virtual environment name in brackets that showed it activated, but it did nothing. It also didn't show error.
Can someone explain what exactly happened to me? I use Windows and PowerShell.
Thank you very much☺️
From PowerShell, you don't want to start the .bat.
You can, but that will start a new cmd process, in which your environment will activate, and then it will kill that process again.
Instead, you'll want to start the .ps1, i.e.:
venv-testing\Scripts\activate.ps1
This will activate the environment in your current PowerShell process, and the activation will persist after running the script.
Depending on your system's configuration, just running this may work:
venv-testing\Scripts\activate
But you may want to explicitly run the .ps1 instead, to avoid a situation where what you do works on some systems, but not on others.

I can't run even simple code of python in my PyCharm IDE. Do need support [duplicate]

This question already has an answer here:
Cannot run program (python) No such file or directory
(1 answer)
Closed 3 months ago.
Screenshot of which when i tried to create a new project2I can't run my python files with pycharm. It says "Error running 'main': Cannot run program "C:\Users\pbrah\AppData\Local\Microsoft\WindowsApps\python3.10.exe" (in directory "C:\Users\pbrah\PycharmProjects\pythonProject9"): CreateProcess error=1920, The file cannot be accessed by the system"
The Screen shot of the mentioned issue
when i had to install Django there was an issues with Django working inpycharm.so I uninstalled and reinstalled PyCharm. Django stated working but now simple python codes doesn't works at all and the above mentioned problem was coming forward.
[screen shot when I try adding new project]
First of all, you should make sure that Python is properly installed in you system.
In CommandPrompt or PowerShell:
python -V
will print your python version, and if the command is working, means that your system can find Python.
Then, get into PyCharm:
Open Settings: File > Settings (or just ctrl + alt + s)
Set the project interpreter: On the settings left tab open "Project:NameOfYourProject"
Point the interpreter to your Python .exe
That being said. I would like to complement that one best practices in development with Python is to have your packages independent from your system. installed in a virtual environment.
So instead of pointing to Python interpreter in your system, you set it to the virtual environment, for example:
C:\path\to\your\project\venv\Scripts\python.exe
EDIT:
Assuming you already have python properly installed in your system, to set up a project, for the first time.
# navigate to your desired folder. I will say just 'C:\Projects'
# set up your project folder
cd C:\Projects
mkdir MyProject
cd MyProject
# upgrade pip and install virtual env
python -m pip install --upgrade pip
pip install virtualenv
# create virtual env
python -m venv venv
Then, inside PyCharm you would set the interpreter to:
D:\Projects\MyProject\venv\Scripts\python.exe

How to use Pycharm venv's local library when running from a Cmd line [duplicate]

This question already has an answer here:
Dyld Error Message when launching PyCharm
(1 answer)
Closed 1 year ago.
let us consider the following PyCharm project which has its own env
My goal is to run the test "test_translator_dispatcher_new_format.py" from a bash. How to instruct the cmd to use that venv and its local library?
open command prompt from current (project) directory
Then activate the virtual environment using this command:
venv\Scripts\activate
then change directory using this command, in your case directory name is tests:
cd <directory_name>
Run python file using this command:
python test_translator_dispatcher_new_format.py

Source command error in Windows 10 on cmder [duplicate]

This question already has answers here:
Issue with virtualenv - cannot activate
(33 answers)
Closed 2 years ago.
I am trying to use this command
source .venv\bin\activate
but I get this error
'source' is not recognized as an internal or external command,
operable program or batch file.
can some one help me with this
1.use cmd rather that cmder
2.to create env use "python -m venv <name_of_your_env>"
3.after this check if it created the environment or no by using "dir"
4.to activate the environment use "<name_of_your_env>\Scripts\activate.bat"
5.to deactivate the environment use "deactivate"
6.to delete the environment completely use "rmdir <name_of_your_env> /s"
You can also refer to this video if my explanation is not clear: https://youtu.be/APOPm01BVrk

Python 2.7 How to load a shared module on a virtual env [duplicate]

This question already has answers here:
Make virtualenv inherit specific packages from your global site-packages
(4 answers)
Closed 6 years ago.
The graph-tool was installed to Ubuntu 16.04.1.
I would like to use the graph-too together with other Python modules which were installed on a virtual env.
Is there any way to use a shared module on a virtual env?
Create your virtualenv with the system site-packages directory included; use the --system-site-packages switch:
$ virtualenv --help
[...]
--system-site-packages
Give the virtual environment access to the global
site-packages.
[...]
You can change this setting by re-running virtualenv on an existing virtual env directory, and disable it again by using the --no-site-packages switch.
Take a look at the virtualenv-docs/configuration page for additional options/scenarios.
--system-site-packages Give the virtual environment access to the global site-packages.
--extra-search-dir=DIR Directory to look for setuptools/pip distributions in. This option can be specified multiple times.
$ virtualenv --extra-search-dir=/path/to/dists
--extra-search-dir=/path/to/other/dists ENV
Also, you can try looking for the answer on stackoverflow, like this one, before you post a new question.

Categories