I was looking for an answer on StackOverflow, but most of them don't solve my entire task.
I have a software called cellprofiler, which works with its own GUI and runs in conda environment on Ubuntu.
I want to automate running this cellprofiler externally with another python script.
My steps:
1) I create a bash script in python which runs the environment and software:
env_activate = 'path_to_sh/activate_env.sh'
with open(env_activate, 'w') as f:
f.write('#!/bin/sh\n')
f.write('. activate cellprofiler && cellprofiler')
f.close()
2) In my python script I then do:
processCP = subprocess.Popen(env_activate, stdout=subprocess.PIPE)
processCP.wait()
but this results in running it in a system python interpreter 3.5 rather than in conda environment
Traceback (most recent call last):
File "/home/**/.local/bin/cellprofiler", line 6, in <module>
from pkg_resources import load_entry_point
File "/home/**/.local/lib/python3.5/site-packages/pkg_resources/__init__.py", line 3126, in <module>
@_call_aside
File "/home/**/.local/lib/python3.5/site-packages/pkg_resources/__init__.py", line 3110, in _call_aside
f(*args, **kwargs)
File "/home/**/.local/lib/python3.5/site-packages/pkg_resources/__init__.py", line 3139, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/home/**/.local/lib/python3.5/site-packages/pkg_resources/__init__.py", line 581, in _build_master
ws.require(__requires__)
File "/home/**/.local/lib/python3.5/site-packages/pkg_resources/__init__.py", line 898, in require
needed = self.resolve(parse_requirements(requirements))
File "/home/**/.local/lib/python3.5/site-packages/pkg_resources/__init__.py", line 784, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'CellProfiler' distribution was not found and is required by the application
Does anyone know why this happens?
UPDATE: The python interpreter I need is python2.7 which is already in the conda environment. Cellprofiler works correctly if calling it in the terminal like:
source activate cellprofiler
cellprofiler