Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_ctypes fail to import when using Conda in poetry 1.1.13 #5907

Closed
grantmwilliams opened this issue Jun 25, 2022 · 8 comments
Closed

_ctypes fail to import when using Conda in poetry 1.1.13 #5907

grantmwilliams opened this issue Jun 25, 2022 · 8 comments
Labels
kind/bug Something isn't working as expected status/external-issue Issue is caused by external project (platform, dep, etc)

Comments

@grantmwilliams
Copy link

  • [x ] I am on the latest Poetry version.
  • [x ] I have searched the issues of this repo and believe that this is not a duplicate.
  • [x ] If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).
  • OS version and name: Windows 10
  • Poetry version: 1.1.13
  • Conda version: 4.13.0
  • Python version(conda): 3.10.4
  • Link of a Gist with the contents of your pyproject.toml file:

Issue

This is the same issue as #4566 and #5059 and was supposed to be fixed in #5008 (I did make sure my local 1.1.13 installation had the same changes in it). I'm unsure if I missed a step, or if there is something more i should do to make sure my environments are correct? I have tried purging the cache and completely uninstalling and reinstalling poetry, but that did not seem to fix the issue for me.

Thanks
- Grant

Some relevant stack traces:

Installing dependencies from lock file

Finding the necessary packages for the current system

Package operations: 10 installs, 0 updates, 0 removalsInstalling pyparsing (3.0.9)

  Stack trace:

  7  ~\AppData\Roaming\pypoetry\venv\lib\site-packages\poetry\installation\executor.py:203 in _execute_operation
      201202try:
    → 203result = self._do_execute_operation(operation)
      204except EnvCommandError as e:
      205if e.e.returncode == -2:

  6  ~\AppData\Roaming\pypoetry\venv\lib\site-packages\poetry\installation\executor.py:277 in _do_execute_operation
      275return 0
      276│
    → 277result = getattr(self, "_execute_{}".format(method))(operation)
      278279if result != 0:

  5  ~\AppData\Roaming\pypoetry\venv\lib\site-packages\poetry\installation\executor.py:412 in _execute_install
      410411def _execute_install(self, operation):  # type: (Install) -> None412return self._install(operation)
      413414def _execute_update(self, operation):  # type: (Update) -> None

  4  ~\AppData\Roaming\pypoetry\venv\lib\site-packages\poetry\installation\executor.py:450 in _install
      448args.insert(2, "-U")
      449│
    → 450return self.run_pip(*args)
      451452def _update(self, operation):

  3  ~\AppData\Roaming\pypoetry\venv\lib\site-packages\poetry\installation\executor.py:301 in run_pip
      299def run_pip(self, *args, **kwargs):  # type: (...) -> int
      300try:
    → 301self._env.run_pip(*args, **kwargs)
      302except EnvCommandError as e:
      303output = decode(e.e.output)

  2  ~\AppData\Roaming\pypoetry\venv\lib\site-packages\poetry\utils\env.py:1160 in run_pip
      1158pip = self.get_pip_command()
      1159cmd = pip + list(args)
    → 1160return self._run(cmd, **kwargs)
      11611162def run_python_script(self, content, **kwargs):  # type: (str, Any) -> str

  1  ~\AppData\Roaming\pypoetry\venv\lib\site-packages\poetry\utils\env.py:1453 in _run
      1452kwargs["env"] = self.get_temp_environ(environ=kwargs.get("env"))

...

   import ctypes
    File "C:\Users\Grant\miniconda3\lib\ctypes\__init__.py", line 8, in <module>
      from _ctypes import Union, Structure, Array
  ImportError: DLL load failed while importing _ctypes: The specified module could not be found.


  at ~\AppData\Roaming\pypoetry\venv\lib\site-packages\poetry\utils\env.py:1195 in _run
      1191output = subprocess.check_output(
      1192cmd, stderr=subprocess.STDOUT, **kwargs
      1193│                 )
      1194except CalledProcessError as e:
    → 1195raise EnvCommandError(e, input=input_)
      11961197return decode(output)
      11981199def execute(self, bin, *args, **kwargs):
@grantmwilliams grantmwilliams added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Jun 25, 2022
@inboxedshoe
Copy link

I'm having the same issue here also with poetry 1.1.13 using pycharm.

@Phantomb
Copy link

Same here!

@atilla00
Copy link

atilla00 commented Aug 4, 2022

Same here

@elbakramer
Copy link

elbakramer commented Sep 23, 2022

It seems that virtualenv omits some required dlls while creating a poetry env in here:

poetry/src/poetry/utils/env.py

Lines 1089 to 1105 in 2def357

args = [
"--no-download",
"--no-periodic-update",
"--python",
executable or sys.executable,
]
if prompt is not None:
args.extend(["--prompt", prompt])
for flag, value in flags.items():
if value is True:
args.append(f"--{flag}")
args.append(str(path))
cli_result = virtualenv.cli_run(args)

Copying ${CONDA_PREFIX}/Library/bin/*ffi*.dlls to poetry env's Script directory solved problem for me.

Use conda info and poetry env info for checking relevant paths.

@neersighted neersighted added status/external-issue Issue is caused by external project (platform, dep, etc) and removed status/triage This issue needs to be triaged labels Sep 23, 2022
@elbakramer
Copy link

Above actually only solved the ctypes problem when tested with poetry run python, but not others including TLS/SSL.
I ended up with copying all the libraries under ${CONDA_PREFIX}/Library/bin/ out to ${CONDA_PREFIX}.

@finswimmer
Copy link
Member

Hello everyone ,

you haven't come back to this issue for a long while. So I assume this is solved in the meantime and I can close this ticket.

Feel free to leave a comment if you disagree.

fin swimmer

@finswimmer finswimmer closed this as not planned Won't fix, can't repro, duplicate, stale Jan 26, 2023
@Phantomb
Copy link

Phantomb commented Jul 3, 2023

Nope, still happens for me on Poetry 1.5.1:

C:\code\[..]>poetry update
Creating virtualenv [env_name] in C:\code\[..]\.venv
Updating dependencies
Resolving dependencies... (8.7s)

Package operations: 9 installs, 0 updates, 0 removals

  • Installing atomicwrites (1.4.1): Failed

  ChefBuildError

  Backend subprocess exited when trying to invoke build_wheel

  Traceback (most recent call last):
    File "C:\Users\[user]\AppData\Roaming\pypoetry\venv\lib\site-packages\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>
      main()
    File "C:\Users\[user]\AppData\Roaming\pypoetry\venv\lib\site-packages\pyproject_hooks\_in_process\_in_process.py", line 335, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
    File "C:\Users\[user]\AppData\Roaming\pypoetry\venv\lib\site-packages\pyproject_hooks\_in_process\_in_process.py", line 251, in build_wheel
      return _build_backend().build_wheel(wheel_directory, config_settings,
    File "C:\Users\[user]~1\AppData\Local\Temp\tmpxwyiw_k_\.venv\lib\site-packages\setuptools\build_meta.py", line 416, in build_wheel
      return self._build_with_temp_dir(['bdist_wheel'], '.whl',
    File "C:\Users\[user]~1\AppData\Local\Temp\tmpxwyiw_k_\.venv\lib\site-packages\setuptools\build_meta.py", line 401, in _build_with_temp_dir
      self.run_setup()
    File "C:\Users\[user]~1\AppData\Local\Temp\tmpxwyiw_k_\.venv\lib\site-packages\setuptools\build_meta.py", line 487, in run_setup
      super(_BuildMetaLegacyBackend,
    File "C:\Users\[user]~1\AppData\Local\Temp\tmpxwyiw_k_\.venv\lib\site-packages\setuptools\build_meta.py", line 338, in run_setup
      exec(code, locals())
    File "<string>", line 16, in <module>
    File "C:\Users\[user]~1\AppData\Local\Temp\tmpxwyiw_k_\.venv\lib\site-packages\setuptools\__init__.py", line 107, in setup
      return distutils.core.setup(**attrs)
    File "C:\Users\[user]~1\AppData\Local\Temp\tmpxwyiw_k_\.venv\lib\site-packages\setuptools\_distutils\core.py", line 172, in setup
      ok = dist.parse_command_line()
    File "C:\Users\[user]~1\AppData\Local\Temp\tmpxwyiw_k_\.venv\lib\site-packages\setuptools\_distutils\dist.py", line 475, in parse_command_line
      args = self._parse_command_opts(parser, args)
    File "C:\Users\[user]~1\AppData\Local\Temp\tmpxwyiw_k_\.venv\lib\site-packages\setuptools\dist.py", line 1132, in _parse_command_opts
      nargs = _Distribution._parse_command_opts(self, parser, args)
    File "C:\Users\[user]~1\AppData\Local\Temp\tmpxwyiw_k_\.venv\lib\site-packages\setuptools\_distutils\dist.py", line 534, in _parse_command_opts
      cmd_class = self.get_command_class(command)
    File "C:\Users\[user]~1\AppData\Local\Temp\tmpxwyiw_k_\.venv\lib\site-packages\setuptools\dist.py", line 979, in get_command_class
      self.cmdclass[command] = cmdclass = ep.load()
    File "C:\Users\[user]\Miniconda3\envs\conda-poetry\lib\importlib\metadata\__init__.py", line 171, in load
      module = import_module(match.group('module'))
    File "C:\Users\[user]\Miniconda3\envs\conda-poetry\lib\importlib\__init__.py", line 126, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
    File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
    File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
    File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
    File "<frozen importlib._bootstrap_external>", line 883, in exec_module
    File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
    File "C:\Users\[user]~1\AppData\Local\Temp\tmpxwyiw_k_\.venv\lib\site-packages\wheel\bdist_wheel.py", line 28, in <module>
      from .macosx_libfile import calculate_macosx_platform_tag
    File "C:\Users\[user]~1\AppData\Local\Temp\tmpxwyiw_k_\.venv\lib\site-packages\wheel\macosx_libfile.py", line 43, in <module>
      import ctypes
    File "C:\Users\[user]\Miniconda3\envs\conda-poetry\lib\ctypes\__init__.py", line 8, in <module>
      from _ctypes import Union, Structure, Array
  ImportError: DLL load failed while importing _ctypes: The specified module could not be found.


  at ~\AppData\Roaming\pypoetry\venv\lib\site-packages\poetry\installation\chef.py:147 in _prepare
      143│
      144│                 error = ChefBuildError("\n\n".join(message_parts))
      145│
      146│             if error is not None:
    → 147│                 raise error from None
      148│
      149│             return path
      150│
      151│     def _prepare_sdist(self, archive: Path, destination: Path | None = None) -> Path:

Note: This error originates from the build backend, and is likely not a problem with poetry but with atomicwrites (1.4.1) not supporting PEP 517 builds. You can verify this by running 'pip wheel --use-pep517 "atomicwrites (==1.4.1)"'.

  • Installing attrs (23.1.0)
  • Installing colorama (0.4.6)
  • Installing more-itertools (9.1.0)
  • Installing packaging (23.1)
  • Installing pluggy (0.13.1)
  • Installing py (1.11.0)
  • Installing wcwidth (0.2.6)

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Something isn't working as expected status/external-issue Issue is caused by external project (platform, dep, etc)
Projects
None yet
Development

No branches or pull requests

7 participants