Search code examples
pythonvirtualenvautobahncrossbar

Using Interpreters from the VirtualEnv


I have started experimenting with Crossbar and WAMP (Web Apps Messaging Protocol) and Im in love with this stuff in just a few weeks time. I answered this stack overflow question (Debugging Crossbar.io app in IntelliJ) as well, however, I have a of question about my own solution.

...

Step 2: Create a pyenv with Python 2 for crossbar.io

    $ pyenv virtualenv 2.7.6 crossbar
    $ pyenv activate crossbar
    (crossbar)$ pip install crossbar
    
...

Step 5: Create a pyenv with Python 3 for app components

    $ pyenv virtualenv 3.4.2 app
    $ pyenv activate app
    (app)$ pip install autobahn
    

Step 6: Create a normal PyCharm project with "app" as a local python environment. I mean use python executable from app pyenv as an interpreter.

...

In step 5 of my solution, I have suggested to create a new virtual python environment for the app component.

Step 6 is purely for IDE to auto-complete and find the local packages, libraries and stuffs from the virtual env above. I reckon, the "crossbar" command doesn't know about this virtual env.

So, when I run the app by ~/.pyenv/versions/crossbar/bin/crossbar start command how to make sure to use the python interpreter from the virtual environment instead? I mean from ~/.pyenv/versions/app/bin/python3?

Is it something to do with the config file? I quickly had a look at the docs (http://crossbar.io/docs/Container-Configuration/) but unfortunately did not find any information about Python interpreter at all.

I tried to put "executable": "~/.pyenv/versions/app/bin/python3" in the config file but it obviously doesn't pass the validation. I mean the crossbar check command fails.

Thank you in Advanced.


Solution

  • If you want to use Python 3 for your app component, and have that component started by Crossbar.io, that means you want a guest worker.

    The way to configure the executable run for the guest worker (which would be Python 3 in your case), is indeed by using the executable parameter.

    The docs are sparse, but here.

    Your safest bet is by using a fully qualified, absolute path in executable pointing to the Python 3 binary within the virtualenv you want to use for your component.

    Note, above applies to guest workers. Crossbar.io native workers include routers and component container. The latter is also able to host Python app components, but only from the same Python that Crossbar.io runs from. The docs (sorry, I know, sparse) is here.