Using subprocess.call() within Pycharm Python virtualenv — how to deactivate venv for subprocessHow do I copy a file in Python?How can I safely create a nested directory?How to get the current time in PythonHow can I make a time delay in Python?How to leave/exit/deactivate a Python virtualenvUse different Python version with virtualenvHow do I get the number of elements in a list in Python?How do I concatenate two lists in Python?Using Python 3 in virtualenvWhat is the difference between venv, pyvenv, pyenv, virtualenv, virtualenvwrapper, pipenv, etc?
Grover algorithm for a database search: where is the quantum advantage?
Is it possible to 'live off the sea'
Why was the Sega Genesis marketed as a 16-bit console?
bash script: "*.jpg" expansion not working as expected inside $(...), for picking a random file
Were Alexander the Great and Hephaestion lovers?
How to forge a multi-part weapon?
Are there any instruments that don't produce overtones?
Should I give professor gift at the beginning of my PhD?
How can I tell the difference between unmarked sugar and stevia?
This riddle is not to see but to solve
What ways have you found to get edits from non-LaTeX users?
How come the nude protesters were not arrested?
Should an arbiter claim draw at a K+R vs K+R endgame?
Passing multiple files through stdin (over ssh)
PhD - Well known professor or well known school?
How is water heavier than petrol, even though its molecular weight is less than petrol?
English word for "product of tinkering"
Compiling c files on ubuntu and using the executable on Windows
Is using haveibeenpwned to validate password strength rational?
1980s live-action movie where individually-coloured nations on clouds fight
How can I get an unreasonable manager to approve time off?
Impedance ratio vs. SWR
Are there any important biographies of nobodies?
Winning Strategy for the Magician and his Apprentice
Using subprocess.call() within Pycharm Python virtualenv — how to deactivate venv for subprocess
How do I copy a file in Python?How can I safely create a nested directory?How to get the current time in PythonHow can I make a time delay in Python?How to leave/exit/deactivate a Python virtualenvUse different Python version with virtualenvHow do I get the number of elements in a list in Python?How do I concatenate two lists in Python?Using Python 3 in virtualenvWhat is the difference between venv, pyvenv, pyenv, virtualenv, virtualenvwrapper, pipenv, etc?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am using Pycharm for Python development. Code is running in Pycharm venv from where I want to call a bash script which activates and deactivates conda environments (this one: https://github.com/lykaust15/DeepSimulator).
So I need to deactivate the Pycharm venv when calling the script via subprocess.call()
, as far as I understand. Otherwise I get errors. How do I do this?
My call is:
result = subprocess.call([deppsim_path, "-i", fasta, "-c", "4",
"-C", "1", "-n", "100",
"-H", os.path.dirname(deppsim_path),
"-o", tmp_path], shell=False)
EDIT:
Some of the errors:
/home/user/path/bin/venv/bin/python /home/user/path/bin/sim_seq.py
Pre-process input genome...
/home/user/path/bin/DeepSimulator/deep_simulator.sh: Zeile 207: deactivate: Datei oder Verzeichnis nicht gefunden
Pre-process input genome done!
Executing the preprocessing step...
Traceback (most recent call last):
File "/home/user/path/bin/DeepSimulator/util/genome_sampling.py", line 5, in <module>
import scipy.stats as st
ImportError: No module named scipy.stats
python pycharm subprocess virtualenv
add a comment |
I am using Pycharm for Python development. Code is running in Pycharm venv from where I want to call a bash script which activates and deactivates conda environments (this one: https://github.com/lykaust15/DeepSimulator).
So I need to deactivate the Pycharm venv when calling the script via subprocess.call()
, as far as I understand. Otherwise I get errors. How do I do this?
My call is:
result = subprocess.call([deppsim_path, "-i", fasta, "-c", "4",
"-C", "1", "-n", "100",
"-H", os.path.dirname(deppsim_path),
"-o", tmp_path], shell=False)
EDIT:
Some of the errors:
/home/user/path/bin/venv/bin/python /home/user/path/bin/sim_seq.py
Pre-process input genome...
/home/user/path/bin/DeepSimulator/deep_simulator.sh: Zeile 207: deactivate: Datei oder Verzeichnis nicht gefunden
Pre-process input genome done!
Executing the preprocessing step...
Traceback (most recent call last):
File "/home/user/path/bin/DeepSimulator/util/genome_sampling.py", line 5, in <module>
import scipy.stats as st
ImportError: No module named scipy.stats
python pycharm subprocess virtualenv
add a comment |
I am using Pycharm for Python development. Code is running in Pycharm venv from where I want to call a bash script which activates and deactivates conda environments (this one: https://github.com/lykaust15/DeepSimulator).
So I need to deactivate the Pycharm venv when calling the script via subprocess.call()
, as far as I understand. Otherwise I get errors. How do I do this?
My call is:
result = subprocess.call([deppsim_path, "-i", fasta, "-c", "4",
"-C", "1", "-n", "100",
"-H", os.path.dirname(deppsim_path),
"-o", tmp_path], shell=False)
EDIT:
Some of the errors:
/home/user/path/bin/venv/bin/python /home/user/path/bin/sim_seq.py
Pre-process input genome...
/home/user/path/bin/DeepSimulator/deep_simulator.sh: Zeile 207: deactivate: Datei oder Verzeichnis nicht gefunden
Pre-process input genome done!
Executing the preprocessing step...
Traceback (most recent call last):
File "/home/user/path/bin/DeepSimulator/util/genome_sampling.py", line 5, in <module>
import scipy.stats as st
ImportError: No module named scipy.stats
python pycharm subprocess virtualenv
I am using Pycharm for Python development. Code is running in Pycharm venv from where I want to call a bash script which activates and deactivates conda environments (this one: https://github.com/lykaust15/DeepSimulator).
So I need to deactivate the Pycharm venv when calling the script via subprocess.call()
, as far as I understand. Otherwise I get errors. How do I do this?
My call is:
result = subprocess.call([deppsim_path, "-i", fasta, "-c", "4",
"-C", "1", "-n", "100",
"-H", os.path.dirname(deppsim_path),
"-o", tmp_path], shell=False)
EDIT:
Some of the errors:
/home/user/path/bin/venv/bin/python /home/user/path/bin/sim_seq.py
Pre-process input genome...
/home/user/path/bin/DeepSimulator/deep_simulator.sh: Zeile 207: deactivate: Datei oder Verzeichnis nicht gefunden
Pre-process input genome done!
Executing the preprocessing step...
Traceback (most recent call last):
File "/home/user/path/bin/DeepSimulator/util/genome_sampling.py", line 5, in <module>
import scipy.stats as st
ImportError: No module named scipy.stats
python pycharm subprocess virtualenv
python pycharm subprocess virtualenv
edited Mar 24 at 17:42
Michael
asked Mar 24 at 17:08
MichaelMichael
313320
313320
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can always call a particular install of python, including virtual environments, using the full path to the python executable. So that's your answer. Use a full path to a python binary that is in the actual Python installation you want to use to run the subprocesses, and you won't involve any virtual environments in running the subprocesses.
As an example, here's what two Python binary paths look like on my system:
> which python
/usr/local/bin/python
> venv development
> which python
/Users/stevenjohnson/envs/development/bin/python
So /usr/local/bin/python is my actual Python 2.7 installation, and /Users/stevenjohnson/envs/development/bin/python is my "development" virtual environment. So if I run the main program in my virtual environment, but if I call /usr/local/bin/python in my subprocess call, The subprocess will run using the base Python 2.7 installation.
Thanks! What confuses me: I am calling a bash script and no python script. How do I tell the subprocess that I want to use a specific Python path inside this bash script? I mean, my call will NOT be like: "/path/to/python script.py -p some paramter -s secondparamter"
– Michael
Mar 24 at 18:22
If you can't modify the bash script, then you really do need to modify the runtime environment, which I was hoping you could avoid. What you probably then need to do is cause the subprocess to run with its PATH environment variable set so that the right python version is found. Mostly what virtualenv does when you switch environments is manipulate the PATH environment variable. So you could just add the path to the python binary you want to use, minus the '/python' at the end, to the front of PATH.
– Steve
Mar 24 at 18:34
Unfortunately, it seems that subprocess calls like check_call and check_output don't take a set of environment variables as input. You'd have to use Popen, which is more complicated. It takes environment variables. Another way to go would be to write your own bash script and call that. the bash script could then set the PATH properly before running the real bash script you want to run.
– Steve
Mar 24 at 18:40
Calling a wrapper script with specific python path like this: result = subprocess.call(["/home/my/propper/python_path", "wrapper_script.py"]). If I call "which python" in the wrapper I still get the python path from the Pycharm venv. Driving me nuts...
– Michael
Mar 24 at 19:37
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55326335%2fusing-subprocess-call-within-pycharm-python-virtualenv-how-to-deactivate-ve%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can always call a particular install of python, including virtual environments, using the full path to the python executable. So that's your answer. Use a full path to a python binary that is in the actual Python installation you want to use to run the subprocesses, and you won't involve any virtual environments in running the subprocesses.
As an example, here's what two Python binary paths look like on my system:
> which python
/usr/local/bin/python
> venv development
> which python
/Users/stevenjohnson/envs/development/bin/python
So /usr/local/bin/python is my actual Python 2.7 installation, and /Users/stevenjohnson/envs/development/bin/python is my "development" virtual environment. So if I run the main program in my virtual environment, but if I call /usr/local/bin/python in my subprocess call, The subprocess will run using the base Python 2.7 installation.
Thanks! What confuses me: I am calling a bash script and no python script. How do I tell the subprocess that I want to use a specific Python path inside this bash script? I mean, my call will NOT be like: "/path/to/python script.py -p some paramter -s secondparamter"
– Michael
Mar 24 at 18:22
If you can't modify the bash script, then you really do need to modify the runtime environment, which I was hoping you could avoid. What you probably then need to do is cause the subprocess to run with its PATH environment variable set so that the right python version is found. Mostly what virtualenv does when you switch environments is manipulate the PATH environment variable. So you could just add the path to the python binary you want to use, minus the '/python' at the end, to the front of PATH.
– Steve
Mar 24 at 18:34
Unfortunately, it seems that subprocess calls like check_call and check_output don't take a set of environment variables as input. You'd have to use Popen, which is more complicated. It takes environment variables. Another way to go would be to write your own bash script and call that. the bash script could then set the PATH properly before running the real bash script you want to run.
– Steve
Mar 24 at 18:40
Calling a wrapper script with specific python path like this: result = subprocess.call(["/home/my/propper/python_path", "wrapper_script.py"]). If I call "which python" in the wrapper I still get the python path from the Pycharm venv. Driving me nuts...
– Michael
Mar 24 at 19:37
add a comment |
You can always call a particular install of python, including virtual environments, using the full path to the python executable. So that's your answer. Use a full path to a python binary that is in the actual Python installation you want to use to run the subprocesses, and you won't involve any virtual environments in running the subprocesses.
As an example, here's what two Python binary paths look like on my system:
> which python
/usr/local/bin/python
> venv development
> which python
/Users/stevenjohnson/envs/development/bin/python
So /usr/local/bin/python is my actual Python 2.7 installation, and /Users/stevenjohnson/envs/development/bin/python is my "development" virtual environment. So if I run the main program in my virtual environment, but if I call /usr/local/bin/python in my subprocess call, The subprocess will run using the base Python 2.7 installation.
Thanks! What confuses me: I am calling a bash script and no python script. How do I tell the subprocess that I want to use a specific Python path inside this bash script? I mean, my call will NOT be like: "/path/to/python script.py -p some paramter -s secondparamter"
– Michael
Mar 24 at 18:22
If you can't modify the bash script, then you really do need to modify the runtime environment, which I was hoping you could avoid. What you probably then need to do is cause the subprocess to run with its PATH environment variable set so that the right python version is found. Mostly what virtualenv does when you switch environments is manipulate the PATH environment variable. So you could just add the path to the python binary you want to use, minus the '/python' at the end, to the front of PATH.
– Steve
Mar 24 at 18:34
Unfortunately, it seems that subprocess calls like check_call and check_output don't take a set of environment variables as input. You'd have to use Popen, which is more complicated. It takes environment variables. Another way to go would be to write your own bash script and call that. the bash script could then set the PATH properly before running the real bash script you want to run.
– Steve
Mar 24 at 18:40
Calling a wrapper script with specific python path like this: result = subprocess.call(["/home/my/propper/python_path", "wrapper_script.py"]). If I call "which python" in the wrapper I still get the python path from the Pycharm venv. Driving me nuts...
– Michael
Mar 24 at 19:37
add a comment |
You can always call a particular install of python, including virtual environments, using the full path to the python executable. So that's your answer. Use a full path to a python binary that is in the actual Python installation you want to use to run the subprocesses, and you won't involve any virtual environments in running the subprocesses.
As an example, here's what two Python binary paths look like on my system:
> which python
/usr/local/bin/python
> venv development
> which python
/Users/stevenjohnson/envs/development/bin/python
So /usr/local/bin/python is my actual Python 2.7 installation, and /Users/stevenjohnson/envs/development/bin/python is my "development" virtual environment. So if I run the main program in my virtual environment, but if I call /usr/local/bin/python in my subprocess call, The subprocess will run using the base Python 2.7 installation.
You can always call a particular install of python, including virtual environments, using the full path to the python executable. So that's your answer. Use a full path to a python binary that is in the actual Python installation you want to use to run the subprocesses, and you won't involve any virtual environments in running the subprocesses.
As an example, here's what two Python binary paths look like on my system:
> which python
/usr/local/bin/python
> venv development
> which python
/Users/stevenjohnson/envs/development/bin/python
So /usr/local/bin/python is my actual Python 2.7 installation, and /Users/stevenjohnson/envs/development/bin/python is my "development" virtual environment. So if I run the main program in my virtual environment, but if I call /usr/local/bin/python in my subprocess call, The subprocess will run using the base Python 2.7 installation.
edited Mar 24 at 17:52
answered Mar 24 at 17:46
SteveSteve
3,9941728
3,9941728
Thanks! What confuses me: I am calling a bash script and no python script. How do I tell the subprocess that I want to use a specific Python path inside this bash script? I mean, my call will NOT be like: "/path/to/python script.py -p some paramter -s secondparamter"
– Michael
Mar 24 at 18:22
If you can't modify the bash script, then you really do need to modify the runtime environment, which I was hoping you could avoid. What you probably then need to do is cause the subprocess to run with its PATH environment variable set so that the right python version is found. Mostly what virtualenv does when you switch environments is manipulate the PATH environment variable. So you could just add the path to the python binary you want to use, minus the '/python' at the end, to the front of PATH.
– Steve
Mar 24 at 18:34
Unfortunately, it seems that subprocess calls like check_call and check_output don't take a set of environment variables as input. You'd have to use Popen, which is more complicated. It takes environment variables. Another way to go would be to write your own bash script and call that. the bash script could then set the PATH properly before running the real bash script you want to run.
– Steve
Mar 24 at 18:40
Calling a wrapper script with specific python path like this: result = subprocess.call(["/home/my/propper/python_path", "wrapper_script.py"]). If I call "which python" in the wrapper I still get the python path from the Pycharm venv. Driving me nuts...
– Michael
Mar 24 at 19:37
add a comment |
Thanks! What confuses me: I am calling a bash script and no python script. How do I tell the subprocess that I want to use a specific Python path inside this bash script? I mean, my call will NOT be like: "/path/to/python script.py -p some paramter -s secondparamter"
– Michael
Mar 24 at 18:22
If you can't modify the bash script, then you really do need to modify the runtime environment, which I was hoping you could avoid. What you probably then need to do is cause the subprocess to run with its PATH environment variable set so that the right python version is found. Mostly what virtualenv does when you switch environments is manipulate the PATH environment variable. So you could just add the path to the python binary you want to use, minus the '/python' at the end, to the front of PATH.
– Steve
Mar 24 at 18:34
Unfortunately, it seems that subprocess calls like check_call and check_output don't take a set of environment variables as input. You'd have to use Popen, which is more complicated. It takes environment variables. Another way to go would be to write your own bash script and call that. the bash script could then set the PATH properly before running the real bash script you want to run.
– Steve
Mar 24 at 18:40
Calling a wrapper script with specific python path like this: result = subprocess.call(["/home/my/propper/python_path", "wrapper_script.py"]). If I call "which python" in the wrapper I still get the python path from the Pycharm venv. Driving me nuts...
– Michael
Mar 24 at 19:37
Thanks! What confuses me: I am calling a bash script and no python script. How do I tell the subprocess that I want to use a specific Python path inside this bash script? I mean, my call will NOT be like: "/path/to/python script.py -p some paramter -s secondparamter"
– Michael
Mar 24 at 18:22
Thanks! What confuses me: I am calling a bash script and no python script. How do I tell the subprocess that I want to use a specific Python path inside this bash script? I mean, my call will NOT be like: "/path/to/python script.py -p some paramter -s secondparamter"
– Michael
Mar 24 at 18:22
If you can't modify the bash script, then you really do need to modify the runtime environment, which I was hoping you could avoid. What you probably then need to do is cause the subprocess to run with its PATH environment variable set so that the right python version is found. Mostly what virtualenv does when you switch environments is manipulate the PATH environment variable. So you could just add the path to the python binary you want to use, minus the '/python' at the end, to the front of PATH.
– Steve
Mar 24 at 18:34
If you can't modify the bash script, then you really do need to modify the runtime environment, which I was hoping you could avoid. What you probably then need to do is cause the subprocess to run with its PATH environment variable set so that the right python version is found. Mostly what virtualenv does when you switch environments is manipulate the PATH environment variable. So you could just add the path to the python binary you want to use, minus the '/python' at the end, to the front of PATH.
– Steve
Mar 24 at 18:34
Unfortunately, it seems that subprocess calls like check_call and check_output don't take a set of environment variables as input. You'd have to use Popen, which is more complicated. It takes environment variables. Another way to go would be to write your own bash script and call that. the bash script could then set the PATH properly before running the real bash script you want to run.
– Steve
Mar 24 at 18:40
Unfortunately, it seems that subprocess calls like check_call and check_output don't take a set of environment variables as input. You'd have to use Popen, which is more complicated. It takes environment variables. Another way to go would be to write your own bash script and call that. the bash script could then set the PATH properly before running the real bash script you want to run.
– Steve
Mar 24 at 18:40
Calling a wrapper script with specific python path like this: result = subprocess.call(["/home/my/propper/python_path", "wrapper_script.py"]). If I call "which python" in the wrapper I still get the python path from the Pycharm venv. Driving me nuts...
– Michael
Mar 24 at 19:37
Calling a wrapper script with specific python path like this: result = subprocess.call(["/home/my/propper/python_path", "wrapper_script.py"]). If I call "which python" in the wrapper I still get the python path from the Pycharm venv. Driving me nuts...
– Michael
Mar 24 at 19:37
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55326335%2fusing-subprocess-call-within-pycharm-python-virtualenv-how-to-deactivate-ve%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown