• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Activate virtual environment from a python script

Resolved: Activate virtual environment from a python script

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I am trying to create a python script for automating some of my personal stuff. In the script, I first want to activate my virtual environment and then do some other tasks, (API calls and processing them). But in the script.py the command that is responsible for activating the virtual environment is not working. I have tried
But this is not activating venv, I have also tried, but this seems not to work
I have also tried
None of the above worked In linux/ubuntu shell script does the job done
I want something similar but using python script, which will be able to activate the virtual environment in the shell/cmd

Answer:

Looks like this answer I linked doesn’t work for Python 3, but in the comments for the answer in that post I found the following from @Calimo which worked for me:
Edit: After some discussion it looks like the real issue was using subprocess without specifying the correct environment. By default subprocess spawns a new process using the global environment. Specify the desired virtual environment by providing the env arg when calling subprocess, ex after activating the virtual environment with the code above:

If you have better answer, please add a comment about this, thank you!

cmd powershell python python-venv virtualenv
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: how to get and read an xml file in a zip file using xml.etree

02/04/2023

Resolved: The ‘Access-Control-Allow-Origin’ header contains multiple values ‘*, *’, but only one is allowed. cors error not resolving

02/04/2023

Resolved: SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘crm.email’ doesn’t exist (Connection: mysql, SQL: select count(*) as aggregate from `email`

02/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.