0

I am trying to compile a Python script into an executable that relies upon packages only installed inside a virtualenv:

sudo su
source /home/me/venv/bin/activate   # Activates virtualenv
cython --embed -o defer4.c defer4.py
gcc -Os -I /usr/include/python3.5m -o defer4 defer4.c -lpython3.5m -lpthread -lm -lutil -ldl

which python3.5
~/venv/bin/python3.5

The defer4.py script relies on pip3 packages installed inside the virtualenv at ~/venv.

The finished executable defer4 fails and suggests that the packages it expects are not present. The error:

me@remote:~$ ./defer4
Traceback (most recent call last):
  File "defer4.py", line 44, in init defer4
    from autobahn.twisted.component import Component, run
  File "/usr/local/lib/python3.5/dist-packages/autobahn/twisted/__init__.py", line 40, in <module>
    from autobahn.twisted.util import sleep
  File "/usr/local/lib/python3.5/dist-packages/autobahn/twisted/util.py", line 31, in <module>
    from twisted.internet.defer import Deferred
ImportError: No module named 'twisted.internet'

In general, I get this error when I run defer4.py outside my virtualenv where twisted isn't installed. Remembering to run it inside my virtualenv always solves this problem.

I tried substituting the /home/me/venv/bin/python3.5 path for the /usr/include/python3.5 in the second command, but this doesn't work (fatal error: Python.h: No such file or directory). Any help?

sscirrus
  • 103
  • 4
  • You forgot to include in your question the specific problem or error you are having. You only said: "The finished executable `defer4` fails and suggests that the packages it expects are not present." But this is way too vague. Be specific. – Michael Hampton Apr 17 '18 at 04:09
  • @MichaelHampton You're right. I've added the specific error. – sscirrus Apr 17 '18 at 15:19

0 Answers0