libtcod / python-tcod

A high-performance Python port of libtcod. Includes the libtcodpy module for backwards compatibility with older projects.
BSD 2-Clause "Simplified" License
404 stars 37 forks source link

No module named 'tcod._libtcod' when importing tcod #109

Closed iamgabrielma closed 3 years ago

iamgabrielma commented 3 years ago

I'm getting the following error when I try to import tcod:

Traceback (most recent call last):
  File "/Users/iamgabrielma/PycharmProjects/roguelikedev2021/main.py", line 1, in <module>
    import tcod
  File "/Users/iamgabrielma/PycharmProjects/roguelikedev2021/venv/lib/python3.9/site-packages/tcod/__init__.py", line 21, in <module>
    from tcod import (
  File "/Users/iamgabrielma/PycharmProjects/roguelikedev2021/venv/lib/python3.9/site-packages/tcod/bsp.py", line 28, in <module>
    import tcod.random
  File "/Users/iamgabrielma/PycharmProjects/roguelikedev2021/venv/lib/python3.9/site-packages/tcod/random.py", line 13, in <module>
    import tcod.constants
  File "/Users/iamgabrielma/PycharmProjects/roguelikedev2021/venv/lib/python3.9/site-packages/tcod/constants.py", line 6, in <module>
    from tcod.color import Color
  File "/Users/iamgabrielma/PycharmProjects/roguelikedev2021/venv/lib/python3.9/site-packages/tcod/color.py", line 7, in <module>
    from tcod._internal import deprecate
  File "/Users/iamgabrielma/PycharmProjects/roguelikedev2021/venv/lib/python3.9/site-packages/tcod/_internal.py", line 10, in <module>
    from tcod.loader import ffi, lib
  File "/Users/iamgabrielma/PycharmProjects/roguelikedev2021/venv/lib/python3.9/site-packages/tcod/loader.py", line 92, in <module>
    from tcod._libtcod import ffi, lib  # type: ignore # noqa: F401
ModuleNotFoundError: No module named 'tcod._libtcod'

I wasn't able to even install the module until I updated the OSX certificates via pip3 install --upgrade certifi, once this was done I was able to install tcod but this new problem appeared. This happens both without and with virtual environment ( tried via venv module, and via PyCharm )

Currently installed: tcod | 12.5.0

HexDecimal commented 3 years ago

Try upgrading tcod to 12.7.0 first:

pip install --upgrade --prefer-binary tcod
iamgabrielma commented 3 years ago

Try upgrading tcod to 12.7.0 first:

Thanks for the reply, I tried that previously but I'm not able to. It does seem that there's still a problem with the certificates?

Requirement already satisfied: tcod in ./venv/lib/python3.9/site-packages (12.5.0)
Collecting tcod
  Using cached tcod-12.7.0.tar.gz (745 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... error
    ERROR: Command errored out with exit status 1:
     command: /Users/iamgabrielma/PycharmProjects/roguelikedev2021/venv/bin/python /Users/iamgabrielma/PycharmProjects/roguelikedev2021/venv/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py prepare_metadata_for_build_wheel /var/folders/yv/b0_wydxn4z538d91c156x3lh0000gn/T/tmpsqttyw6w
         cwd: /private/var/folders/yv/b0_wydxn4z538d91c156x3lh0000gn/T/pip-install-4zkbbjev/tcod_7db5647eafd8472aafb3f4d7d12cf79e
    Complete output (78 lines):
    Downloading https://www.libsdl.org/release/SDL2-2.0.5.dmg
    Traceback (most recent call last):
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 1346, in do_open
        h.request(req.get_method(), req.selector, req.data, headers,
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1253, in request
        self._send_request(method, url, body, headers, encode_chunked)
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1299, in _send_request
        self.endheaders(body, encode_chunked=encode_chunked)
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1248, in endheaders
        self._send_output(message_body, encode_chunked=encode_chunked)
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1008, in _send_output
        self.send(msg)
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 948, in send
        self.connect()
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1422, in connect
        self.sock = self._context.wrap_socket(self.sock,
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 500, in wrap_socket
        return self.sslsocket_class._create(
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1040, in _create
        self.do_handshake()
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1309, in do_handshake
        self._sslobj.do_handshake()
    ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/Users/iamgabrielma/PycharmProjects/roguelikedev2021/venv/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 280, in <module>
        main()
      File "/Users/iamgabrielma/PycharmProjects/roguelikedev2021/venv/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 263, in main
        json_out['return_val'] = hook(**hook_input['kwargs'])
      File "/Users/iamgabrielma/PycharmProjects/roguelikedev2021/venv/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 133, in prepare_metadata_for_build_wheel
        return hook(metadata_directory, config_settings)
      File "/private/var/folders/yv/b0_wydxn4z538d91c156x3lh0000gn/T/pip-build-env-q_o5hk39/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 166, in prepare_metadata_for_build_wheel
        self.run_setup()
      File "/private/var/folders/yv/b0_wydxn4z538d91c156x3lh0000gn/T/pip-build-env-q_o5hk39/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 150, in run_setup
        exec(compile(code, __file__, 'exec'), locals())
      File "setup.py", line 104, in <module>
        setup(
      File "/private/var/folders/yv/b0_wydxn4z538d91c156x3lh0000gn/T/pip-build-env-q_o5hk39/overlay/lib/python3.9/site-packages/setuptools/__init__.py", line 153, in setup
        return distutils.core.setup(**attrs)
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/core.py", line 108, in setup
        _setup_distribution = dist = klass(attrs)
      File "/private/var/folders/yv/b0_wydxn4z538d91c156x3lh0000gn/T/pip-build-env-q_o5hk39/overlay/lib/python3.9/site-packages/setuptools/dist.py", line 455, in __init__
        _Distribution.__init__(self, {
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/dist.py", line 292, in __init__
        self.finalize_options()
      File "/private/var/folders/yv/b0_wydxn4z538d91c156x3lh0000gn/T/pip-build-env-q_o5hk39/overlay/lib/python3.9/site-packages/setuptools/dist.py", line 801, in finalize_options
        ep(self)
      File "/private/var/folders/yv/b0_wydxn4z538d91c156x3lh0000gn/T/pip-build-env-q_o5hk39/overlay/lib/python3.9/site-packages/setuptools/dist.py", line 808, in _finalize_setup_keywords
        ep.load()(self, ep.name, value)
      File "/private/var/folders/yv/b0_wydxn4z538d91c156x3lh0000gn/T/pip-build-env-q_o5hk39/overlay/lib/python3.9/site-packages/cffi/setuptools_ext.py", line 219, in cffi_modules
        add_cffi_module(dist, cffi_module)
      File "/private/var/folders/yv/b0_wydxn4z538d91c156x3lh0000gn/T/pip-build-env-q_o5hk39/overlay/lib/python3.9/site-packages/cffi/setuptools_ext.py", line 49, in add_cffi_module
        execfile(build_file_name, mod_vars)
      File "/private/var/folders/yv/b0_wydxn4z538d91c156x3lh0000gn/T/pip-build-env-q_o5hk39/overlay/lib/python3.9/site-packages/cffi/setuptools_ext.py", line 25, in execfile
        exec(code, glob, glob)
      File "build_libtcod.py", line 217, in <module>
        SDL2_PARSE_PATH = unpack_sdl2(SDL2_PARSE_VERSION)
      File "build_libtcod.py", line 163, in unpack_sdl2
        sdl2_arc = get_sdl2_file(version)
      File "build_libtcod.py", line 152, in get_sdl2_file
        urlretrieve(sdl2_remote_file, sdl2_local_file)
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 239, in urlretrieve
        with contextlib.closing(urlopen(url, data)) as fp:
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 214, in urlopen
        return opener.open(url, data, timeout)
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 517, in open
        response = self._open(req, data)
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 534, in _open
        result = self._call_chain(self.handle_open, protocol, protocol +
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 494, in _call_chain
        result = func(*args)
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 1389, in https_open
        return self.do_open(http.client.HTTPSConnection, req,
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 1349, in do_open
        raise URLError(err)
    urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)>
HexDecimal commented 3 years ago

This could be affected by were you got Python from, since it's really weird on MacOS. The certificate issues might be related, but things have already gone wrong if tcod-12.7.0.tar.gz is being used. Any source installs will run into the issue with #108.

You can't use a version of MacOS older than Mavericks, which might mean you can't use a build of Python which is compiled for a version of MacOS earlier than Mavericks. I forget the details of this.

Here's a more aggressive pip command which will still fail but won't try to compile tcod:

pip install --upgrade --only-binary tcod --no-cache-dir tcod

I'm not sure which versions of Python to recommend on MacOS. I can only think of the official Python site or brew.sh for getting Python. You need an installation compatible with tcod-12.7.0-cp36-abi3-macosx_10_9_x86_64.whl

iamgabrielma commented 3 years ago

Thanks for the follow-up, I'm using Big Sur (Chip M1), which has given me continuous headaches when trying to use python modules so far. I ended being able to update tcod to 12.7 by updating the certificates following this SO script.

Requirement already satisfied: tcod in ./venv/lib/python3.9/site-packages (12.7.0)

Now it still seems that is not able to find tcod._libtcod, but with a slightly different error:

Traceback (most recent call last):
  File "/Users/iamgabrielma/PycharmProjects/roguelikedev2021/main.py", line 1, in <module>
    import tcod
  File "/Users/iamgabrielma/PycharmProjects/roguelikedev2021/venv/lib/python3.9/site-packages/tcod/__init__.py", line 12, in <module>
    from tcod import bsp, color, console, context, event, image, los, map, noise, path, random, tileset
  File "/Users/iamgabrielma/PycharmProjects/roguelikedev2021/venv/lib/python3.9/site-packages/tcod/bsp.py", line 28, in <module>
    import tcod.random
  File "/Users/iamgabrielma/PycharmProjects/roguelikedev2021/venv/lib/python3.9/site-packages/tcod/random.py", line 14, in <module>
    import tcod.constants
  File "/Users/iamgabrielma/PycharmProjects/roguelikedev2021/venv/lib/python3.9/site-packages/tcod/constants.py", line 5, in <module>
    from tcod.color import Color
  File "/Users/iamgabrielma/PycharmProjects/roguelikedev2021/venv/lib/python3.9/site-packages/tcod/color.py", line 7, in <module>
    from tcod._internal import deprecate
  File "/Users/iamgabrielma/PycharmProjects/roguelikedev2021/venv/lib/python3.9/site-packages/tcod/_internal.py", line 10, in <module>
    from tcod.loader import ffi, lib
  File "/Users/iamgabrielma/PycharmProjects/roguelikedev2021/venv/lib/python3.9/site-packages/tcod/loader.py", line 90, in <module>
    from tcod._libtcod import ffi, lib  # type: ignore # noqa: F401
ImportError: dlopen(/Users/iamgabrielma/PycharmProjects/roguelikedev2021/venv/lib/python3.9/site-packages/tcod/_libtcod.abi3.so, 2): Library not loaded: @rpath/SDL2.framework/Versions/A/SDL2
  Referenced from: /Users/iamgabrielma/PycharmProjects/roguelikedev2021/venv/lib/python3.9/site-packages/tcod/_libtcod.abi3.so
  Reason: image not found

This part here:

ImportError: dlopen(/Users/iamgabrielma/PycharmProjects/roguelikedev2021/venv/lib/python3.9/site-packages/tcod/_libtcod.abi3.so, 2): Library not loaded: @rpath/SDL2.framework/Versions/A/SDL2

There's no such framework on OSX /Library/Frameworks/ , just the Python.framework , I'll give it a go later on and keep the thread updated.

HexDecimal commented 3 years ago

Your logs keep leaving out the tags used in the wheels you're building with pip. Which would help me greatly in knowing what's going on.

iamgabrielma commented 3 years ago

I'm not acquainted how Python wheels work, nor I'm sure how can I provider more info to help you further. Anything specific I can run or share on terminal to share more information? I found these logs back from the initial install that seem to refer to the wheels used:

 Collecting tcod
  Downloading tcod-12.7.0.tar.gz (745 kB)
     |████████████████████████████████| 745 kB 1.2 MB/s 
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Requirement already satisfied: numpy~=1.10 in /Users/iamgabrielma/Library/Python/3.8/lib/python/site-packages (from tcod) (1.21.0rc1)
Collecting typing-extensions
  Downloading typing_extensions-3.10.0.0-py3-none-any.whl (26 kB)
Collecting cffi~=1.13
  Using cached cffi-1.14.5.tar.gz (475 kB)
Collecting pycparser
  Using cached pycparser-2.20-py2.py3-none-any.whl (112 kB)
Building wheels for collected packages: tcod, cffi
  Building wheel for tcod (PEP 517) ... done
  Created wheel for tcod: filename=tcod-12.7.0-cp38-cp38-macosx_10_14_6_arm64.whl size=1572544 sha256=0a14cca7f60cdc4cb33e409649b4491f2e599568204740316a6c36c6cb6d0327
  Stored in directory: /Users/iamgabrielma/Library/Caches/pip/wheels/07/7d/22/76727ff4454b3df78ea300d43bfcceed7500d8647055f738cb
  Building wheel for cffi (setup.py) ... done
  Created wheel for cffi: filename=cffi-1.14.5-cp38-cp38-macosx_10_14_6_arm64.whl size=258284 sha256=d41c28bc1acc3b2c75dd0149bbbffe9f8da58012344f5d95c322ecaeb64db393
  Stored in directory: /Users/iamgabrielma/Library/Caches/pip/wheels/04/f4/d8/7ce287ba472b28f118422005f3e885c8124dd5dd092889685b
Successfully built tcod cffi
Installing collected packages: pycparser, typing-extensions, cffi, tcod
Successfully installed cffi-1.14.5 pycparser-2.20 tcod-12.7.0 typing-extensions-3.10.0.0
HexDecimal commented 3 years ago

Thanks, this was what I was looking for: tcod-12.7.0-cp38-cp38-macosx_10_14_6_arm64.whl

ARM64 is a new architecture that I don't have automated builds for. I'll need to check if I can build those.

HexDecimal commented 3 years ago

Version 12.7.1 now as ARM64 builds, but they're cross-compiled so I can't actually test them. You'll need to upgrade and report back.

iamgabrielma commented 3 years ago

Version 12.7.1 now as ARM64 builds, but they're cross-compiled so I can't actually test them. You'll need to upgrade and report back.

You're the best, it works now!