clj-python / libpython-clj

Python bindings for Clojure
Eclipse Public License 2.0
1.08k stars 68 forks source link

Question: How to directing libpython-clj at a virtualenv (without activating it) #111

Closed aeftimia closed 4 years ago

aeftimia commented 4 years ago

What would be the recommended way to directing libpython-clj to a virtualenv. I'm looking for a way without having to explicitly activate the virtualenv prior to running. It seems that calling initialize! would be the appropriate way to go. However it also seems like initalize! is called just upon requireing libpython-clj.python (without giving the user a chance to override it).

Thanks!

cnuernber commented 4 years ago

What has worked in the past has been having a clj file you know is loaded earlier than the rest of your system that calls `libpython-clj.python/initialize!'.

I personally strongly recommend using docker containers to control your environment. We have an example of a docker container that mounts the local project directory as the current user and from there so you have access to all your local project data and code but your execution environment is more controlled.

aeftimia commented 4 years ago

I'd love to use a container, but the requirements of the project I'm working on don't allow that. The goal is to be able to package Python code within a Java project, and libpython-clj is my best (only?) option since Jython doesn't support 3+.

I learned about the use statement and got your suggestion working. Thanks!