Virtual Environment's Activate Does not work - python

I tried to install VirtualEnv on the latest version of Python. Even though it is successfully installed, when I create a new virtual environment and try to activate it, it switches to a new line as nothing has happened.
I checked the folder, I'm entering the right path, it's not in "bin" folder. I'm not sure what's causing the problem.
I'm on Windows and I'm not using PowerShell.

1)Run Powershell as Administrator
Run the following command in powershell: Set-ExecutionPolicy Unrestricted
Rerun the activation command: > venv\Scripts\activate.ps1

Related

Activating Python Virtual Environment on Windows 11

I am trying to create a venv virtual enviroment for Python in Window's command prompt. I created the enviroment; however, I am having difficulties using it because when I run the "activate" command it is not working. I think the problem is related to that the virtual enviroment does not have a scripts file like other window machines do, but rahter a bin file which has the activate script. When I run the activate command with the bin in the file directory I still get an error.
enter image description here
I have been trying to solve the problem for the past 4-5 hours and am completely stuck. I tried destroying and reconstructing the virtual enviroment, I tried using different extensions (.bat, .exe, .ps1, and just \activate), and tried using powershell.
Please let me know if you have any ideas what I am doing wrong!
Open a command prompt terminal by either searching command prompt in the Windows search bar, or press the Windows Key + R and enter cmd.
Create the virtual environment in a desired directory using the following command:
python -m venv env
This will create a new folder called env inside the directory where you executed the command.
You can activate the created virtual environment by running the following command in the same directory where you executed the last command:
cd env/Scripts && activate && cd ../../
I hope this helps.
python -m venv venv
#To run this command prompt on python terminal to create a virtual environment
venv\Scripts\activate
#Run this command prompt on python terminal

Python django cant activate virtual enviroment

I can't activate virtual enviroment and get 'cannot be loaded because running scripts is disabled on this system'
I tried to write 'activate' and './activate' but both dont work
To solve this error:
Simply you can open powershell as admin and then execute below command:
set-executionpolicy remotesigned
You will be prompted to accept the change, type A(Yes to all), and press ENTER on your keyboard to allow the change.
Close the PowerShell admin window, and go back to the PowerShell Window where you got the error. Run the command below
venv\Scripts\activate
And now your error is solved.
If you are using virtualenv.
venv bin/activate
I am condering venv is your envionment folder and you're on the folder containing your virtual environment.
PS: you can create virtual environment using following command
virtualenv venv -p python3

Anaconda will not run

I've installed Anaconda 3, version 2020.02 (current version straight from the website, 64 bit), and cannot figure out how to run it. When I search (on Windows) for Anaconda prompt or Anaconda navigator, I cannot find either. When I try to run any commands like conda init or anaconda-navigator on the command line, it says 'conda is not recognized as an internal or external command'. Yet it did install successfully (supposedly); the installed Anaconda3 files are where they should be. I have added the proper filepath to my system PATH variable, and added Anaconda3/Scripts to the PATH variable as well; neither of these make a difference. Typing 'where conda' on command line results in 'INFO: Could not find files for the given patterns'. I have uninstalled Anaconda and reinstalled an earlier version, and this does not work either. What next steps should I take to try to get Anaconda to run?
Install Anaconda and don't change any of the default settings. This will install Anaconda in your user profile and add the c:\users\user_name\AppData\Anaconda3\condabin folder to your system path. But before you can actually use Anaconda, you'll need to activate an environment. Either use the Anaconda prompt shortcut or open a cmd shell and type conda activate. If the the prompt doesn't change to (base) C:\users\user_name> Anaconda won't work. Adding ../Anaconda3/Scripts to the PATH simply isn't sufficient. If necessary go to the c:\users\user_name\AppData\Anaconda3\condabin folder and run conda init again.

Conda environment activation fails in VS Code

When I launch a Python terminal or use Shift+Enter to run code from my Python Files through VS Code on Windows, I get a message:
This Python interpreter is in a conda environment, but the environment
has not been activated. Libraries may fail to load. To activate this
environment please see https://conda.io/activation.
I get a Python prompt. The code runs as expected. If I exit() that prompt and run "conda activate myenv", the environment activates and I can then run python using the desired environment. However, I can't seem to figure out why it's not activating by default.
I have the MS Python module loaded. Conda is up to date and in my system path. I've installed Conda into cmd and powershell. And the expect "activate" command works if I quit python and type it in. Any ideas what I might be missing?
Please check if you have this setting in your settings.json file,
"python.pythonPath": "<anacondapath>\\envs\\<yourenv>\\python.exe",
This should automatically load the conda environment for you.

"pip install somepackage" freezes powershell

I've been using python in both my office pc and my personal laptop and on both machines typing in powershell:
pip install somepackage
works normally.
Strangely enough, when I attempt to do it on my personal desktop, powershell remains on halt infinitely.
I found a solution for this by doing:
python -m pip install somepackage
The above is fine, and I can live with typing an extra 8 characters whenever I want to install a new package but I'm curious to understand what is happening.
Thanks :)
PS: I have added C:/Python27/Scripts to Path in the system variables already and it didn't solve the issue.
pip.exe is located in C:\Python27\Scripts. You need to add that folder to your PATH environment variable. If you added it to the system environment you need to start a new PowerShell console to make the change become effective.
If you want the path to become available in the current console you need to add it to the PATH variable in the current console as well (the console gets a copy of the environment when it starts, it doesn't pick up changes to the system or user environment at runtime):
$env:Path += ';C:\Python27\Scripts'
pip install somepackage
However, C:\Python27\Scripts not being included in the PATH should only result in an error message that PowerShell doesn't recognize the command. It shouldn't freeze the console. Perhaps there's some other cmdlet/command/function/alias named pip that gets executed instead. Try running Get-Command pip to verify that.

Categories

Resources