Python Forum
Can Not Activate Environment
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can Not Activate Environment
#1
I think I created an environment correctly sometime in recent past but I can not get it to activate now. Below is command result and my directory tree. I know this is basic but what am I missing?
env is the environment name. I 1st tried the shorter $ source env/bin/activate with same results.
If i look in the env directory it has a bin folder and a activate and Activate.ps1 text file.

mark@mark-Latitude-E7240:~$ source MyComputer/mark/Python_Environments/env/bin/activate
bash: MyComputer/mark/Python_Environments/env/bin/activate: No such file or directory
mark@mark-Latitude-E7240:~$ 
Reply
#2
Here a basic run
# Make
tom@tom-VirtualBox:~$ python -m venv my_env
# Cd in
tom@tom-VirtualBox:~$ cd my_env/
# Activate
tom@tom-VirtualBox:~/my_env$ source bin/activate
(my_env) tom@tom-VirtualBox:~/my_env$ which python
/home/tom/my_env/bin/python
Let say i'm not in my_env folder and want to activate,then have to give path to folder.
tom@tom-VirtualBox:~$ source my_env/bin/activate
(my_env) tom@tom-VirtualBox:~$ pip -V
pip 21.2.4 from /home/tom/my_env/lib/python3.10/site-packages/pip (python 3.10)

(my_env) tom@tom-VirtualBox:~$ deactivate
# Outside(deactivate) pip use Python version on OS
tom@tom-VirtualBox:~$ pip -V
pip 21.2.4 from /home/tom/.pyenv/versions/3.10.2/lib/python3.10/site-packages/pip (python 3.10)
Reply
#3
When you build an environment, you do so against a particular version of python. If that version goes away (either manually or because some package manager upgrades python and thinks you don't need the old version any longer), then the virtual environment can't find it any longer and you get that message.

Either put the original version back on the box or recreate your virtual environment against whatever version of python is now installed.
Reply
#4
Thank you both. Through above direction i resolved my issue. I checked and the version was still the same, however; when I changed my directory to where my environment was, the activation worked.
I know now to be in the directory as the environment i am trying to activate.
Reply
#5
You don't need to be in the same directory, you just need to specify the path.
Reply
#6
(Mar-05-2022, 06:13 AM)deanhystad Wrote: You don't need to be in the same directory, you just need to specify the path.

How so? Shouldn't the activation script provide the path?
Reply
#7
bowlofred Wrote:How so? Shouldn't the activation script provide the path?
No when outside of environment folder must specificity path to folder.
# Can not find it
tom@tom-VirtualBox:~$ source bin/activate
bash: bin/activate: No such file or directory

# If give path ok
tom@tom-VirtualBox:~$ source my_env/bin/activate
(my_env) tom@tom-VirtualBox:~$ deactivate
tom@tom-VirtualBox:~$
Same on windows but there there is no source,so then just give path to activate.bat on the environment that want to activate.
Let say i'm in root C:\ and want to activate a environment on G:\ drive.
C:\
λ G:\div_code\flaskex_env\Scripts\activate.bat

(flaskex_env) C:\
λ pip -V
pip 21.1.1 from g:\div_code\flaskex_env\lib\site-packages\pip (python 3.9)

(flaskex_env) C:\
λ deactivate
C:\
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python win32com.client: What are the syntax to open exe file & activate its window? JaneTan 0 4,189 Oct-14-2020, 09:09 AM
Last Post: JaneTan
  Activate Winodw/ Set focus biprabu 0 1,658 Sep-07-2020, 04:05 AM
Last Post: biprabu
  Auto activate conda env in Pycharm terminal ntuttle 0 4,770 Mar-08-2019, 03:56 PM
Last Post: ntuttle
  virtualenv activate.ps1 hash error po20 2 3,818 Jan-13-2018, 09:21 AM
Last Post: po20
  How do I activate my script when another program opens? jhave_21 3 3,813 Nov-23-2017, 08:29 AM
Last Post: heiner55
  Help to activate the "USB Modem" with Python karlo123 4 4,863 Sep-17-2017, 08:40 PM
Last Post: sparkz_alot
  Activate Virtual Environment and Help to get started with Python Adelton 4 7,210 Feb-14-2017, 06:11 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020