bendudson / py4cl

Call python from Common Lisp
Other
234 stars 31 forks source link

Question #15

Closed rpgoldman closed 3 years ago

rpgoldman commented 5 years ago

What's the best way to use this with a virtual environment?

digikar99 commented 5 years ago

You should be good with setting the *python-command*. At the least, it picks up the libraries from the miniconda base env - I haven't tested it with non-base env.

(setf py4cl:*python-command* "/home/user/miniconda3/bin/python") ; or wherever the python binary is
(python-stop) ; if the previous python process was running
(python-start)

Edit: Corrected pystart/pystop to python-start/python-stop.

bendudson commented 5 years ago

Thanks for replying, sorry for the delay. I have not tried it with virtual environments, but it should be equivalent to running the specified *python-command* from the command line.

Note in the current "master" and quicklisp version the functions are python-stop and python-start

digikar99 commented 5 years ago

Note in the current "master" and quicklisp version the functions are python-stop and python-start

Ah, yes: thanks for the correction!

rpgoldman commented 5 years ago

I've been using mkvirtualenv, which seems like it's not just a pure python thing -- it also affects the shell environment. So I wonder if just changing the python program is enough, and I also wonder if using straight launch-program versus launching the shell will be successful.

digikar99 commented 5 years ago

At least with miniconda, it is enough. Without restarting slime, I get appropriate results for

(progn
  (python-stop)
  (python-exec "import sys") 
  (python-eval "sys.path")) 
;; try using this to check yours

depending on the value of *python-command*.

ghost commented 4 years ago

It seems to work nicely with non-base envs too —I'm using it to play around with gym examples and zero issues so far. It's toy usage though, so don't rely too much on this 😅