DEV Community

miheer vaidya
miheer vaidya

Posted on

Julia ❤ Python

If you have read my earlier posts you know I love multilingual programming. One important part of multilingual programming is how to interface one language with other. Typically this is called FFI or foreign function interface. At the lowest level often there are libraries (aka bindings) to talk across languages or across implementations of same language e.g. libffi. In my undergrad we did a group project where we created language bindings to separate algorithmic part written in python and opencv and X11 logic in c.

Recently I have started learning Julia which promises programmer productivity of Python and performance of C*. Julia PyCall library provides FFI for Python. After multiple unsuccessful attempts to use PyCall on Windows, I found out one needs to set PYTHONPATH environment variable in addition to PYTHON environment variable in Julia script to use specific python virtual environment. PyCall can automatically install conda and packages from conda but seems like if one wishes to use virtualenvironment and pip one needs to set these environment variables manually in the Julia script.

ENV["PYTHON"] = raw"<pathToVirtualEnv>\Scripts\python.exe"
ENV["PYTHON"] = raw"<pathToVirtualEnv>\lib\site-packages"
# Note the `raw` string literal in Julia which eliminates
# need of escaping `\` in Windows paths.
Enter fullscreen mode Exit fullscreen mode

Hope you find it useful.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more