necaris / cuid.py

A fast, scalable unique ID generator for Python
BSD 2-Clause "Simplified" License
64 stars 8 forks source link

The package is not installed correctly with poetry on Mac M1 #20

Closed attila-papai closed 1 year ago

attila-papai commented 1 year ago

Hey,

I have a MacBook Pro M1 and when I try to install cuid package with poetry and use it, I get an error that the module cannot be found.

$> poetry add cuid
Using version ^0.3 for cuid

Updating dependencies
Resolving dependencies... (1.4s)

Writing lock file

Package operations: 1 install, 0 updates, 0 removals

  - Installing cuid (0.3)
$> python
Python 3.10.2 (main, Mar  4 2022, 16:44:01) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from cuid import cuid
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cuid'
>>> import cuid
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cuid'

If I install it with pip it works, but my project uses poetry so can't just install it with pip:

$> pip install cuid
Collecting cuid
  Using cached cuid-0.3-py2.py3-none-any.whl
Installing collected packages: cuid
Successfully installed cuid-0.3
$> python
Python 3.10.2 (main, Mar  4 2022, 16:44:01) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from cuid import cuid
>>> cuid()
'cl6geago50000pnv3cs2jmaj0'
necaris commented 1 year ago

I suspect the main problem is that Poetry natively installs dependencies into a virtual environment, and you haven't activated it. If I use poetry run python to ensure the virtual environment is activated, I can't reproduce this on an M1 Macbook Pro:

❯ poetry init

This command will guide you through creating your pyproject.toml config.

Package name [foo]:
Version [0.1.0]:
Description []:  an example project
Author [None, n to skip]:  n
License []:  AGPL
Compatible Python versions [^3.11]:  >3.6

Would you like to define your main dependencies interactively? (yes/no) [yes] no
Would you like to define your development dependencies interactively? (yes/no) [yes] no
Generated file

[tool.poetry]
name = "foo"
version = "0.1.0"
description = "an example project"
authors = ["Your Name <you@example.com>"]
license = "AGPL"
readme = "README.md"

[tool.poetry.dependencies]
python = ">3.6"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

Do you confirm generation? (yes/no) [yes] y

❯ poetry add cuid
Using version ^0.3 for cuid

Updating dependencies
Resolving dependencies... (6.6s)

Writing lock file

Package operations: 1 install, 0 updates, 0 removals

  • Installing cuid (0.3)

❯ poetry run python
Python 3.11.1 (main, Dec 23 2022, 09:28:24) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cuid
>>> cuid.cuid()
'clew2f85r00002jd9lx2lzedn'

Whereas if I don't activate a virtual environment, or anything...

❯ python3
Python 3.9.6 (default, Oct 18 2022, 12:41:40)
[Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cuid
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cuid'

I'm closing it as I'm not able to reproduce this, but please reopen if you still have this issue!