go-python / gopy

gopy generates a CPython extension module from a go package.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Python Package Install

acminor opened this issue · comments

OS: fedora
PYTHON: python3
MISC: using python3 venv

I built a package and installed it with pip install .

  • I could not get python setup.py install to work because of egg file issues.

Afterwards, I kept getting the following error:

Traceback (most recent call last):
  File "test.py", line 1, in <module>
    import packet_compression.packet_compression as pc
  File "/home/{...}/env/lib64/python3.7/site-packages/packet_compression/packet_compression.py", line 14, in <module>
    import _packet_compression
ModuleNotFoundError: No module named '_packet_compression'

For some reason, the chdir inside of packet_compression.py was having issues.
I managed a fix with the following code. Can other people confirm the working of the code and if gopy needs to be updated to reflect this.

import os,sys,inspect,collections
cwd = os.getcwd()
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
os.chdir(currentdir)
old_path = sys.path
sys.path += [os.getcwd()] # added to make finding _packet_compression possible
import _packet_compression
sys.path = old_path
os.chdir(cwd)

It appears to be some issue with python3 not searching the current directory for python files.

  • Note: this does not occur if using the interactive compiler.
  • Note: this only occurs when using python3 main.py to execute a program.

This could be related to the work I have pending in #245 which is to make the generated import statements be absolute. Python3 expects absolute imports whereas python2 used to check the current directory of the file.

yep assuming @justinfx fixes worked -- open new issue if not.