Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No module named 'Cython' with pip installation of tar.gz

I use Poetry to build tar.gz and whl files for my example package (https://github.com/iamishalkin/cyrtd) and then try to install package inside pipenv environment. tar.gz installation fails and this is a piece of logs:

$ poetry build
...
$ pip install dist/cyrtd-0.1.0.tar.gz
Processing c:\work2\cyrtd\dist\cyrtd-0.1.0.tar.gz
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Requirement already satisfied: cython<0.30.0,>=0.29.13 in c:\users\ivan.mishalkin\.virtualenvs\cyrtd-tpdvsw8x\lib\site-packages (from cyrtd==0.1.0) (0.29.15)
Building wheels for collected packages: cyrtd
  Building wheel for cyrtd (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
...
from Cython.Build import cythonize
  ModuleNotFoundError: No module named 'Cython'  
  ----------------------------------------
  ERROR: Failed building wheel for dxpyfeed
Failed to build dxpyfeed
ERROR: Could not build wheels for dxpyfeed which use PEP 517 and cannot be installed directly

Cython is installed and is callable from virtual interpreter. Even in logs it is written, that requirements for cython are satisfied. What is strange - everything worked fine couple months ago. I also tried conda venv, upgraded cython and poetry, nothing helped. Also tried weakly related workaround from setup_requires with Cython? - still no luck

UPD: I found some dirty workaround here: https://luminousmen.com/post/resolve-cython-and-numpy-dependencies

The idea is to add

from setuptools import dist
dist.Distribution().fetch_build_eggs(['cython'])

before Cython.Build import

After this I get these logs:

$ pip install dist/cyrtd-0.1.0.tar.gz
Processing c:\work2\cyrtd\dist\cyrtd-0.1.0.tar.gz
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Requirement already satisfied: cython<0.30.0,>=0.29.13 in c:\users\ivan.mishalkin\.virtualenvs\cyrtd-tpdvsw8x\lib\site-packages (from cyrtd==0.1.0) (0.29.15)
Building wheels for collected packages: cyrtd
  Building wheel for cyrtd (PEP 517) ... done
  Created wheel for cyrtd: filename=cyrtd-0.1.0-cp37-cp37m-win_amd64.whl size=33062 sha256=370a90657759d3183f3c11ebbdf1d23c3ca857d41dd45a86386ba33a6baf9a07
  Stored in directory: c:\users\ivan.mishalkin\appdata\local\pip\cache\wheels\45\d1\6b\52daecf1cc5234ca4d9e9e49b2f195e7adb83941424116432e
Successfully built cyrtd
Installing collected packages: cyrtd
  Attempting uninstall: cyrtd
    Found existing installation: cyrtd 0.1.0
    Uninstalling cyrtd-0.1.0:
      Successfully uninstalled cyrtd-0.1.0
Successfully installed cyrtd-0.1.0

Still looking for a better solution

UPD2: main files content: build.py:

from setuptools import Extension
from Cython.Build import cythonize

cyfuncs_ext = Extension(name='cyrtd.cymod.cyfuncs',
                        sources=['cyrtd/cymod/cyfuncs.pyx']
                        )

EXTENSIONS = [
    cyfuncs_ext
]

def build(setup_kwargs):
    setup_kwargs.update({
        'ext_modules': cythonize(EXTENSIONS, language_level=3),
        'zip_safe': False,
        'setup_requires':['setuptools>=18.0', 'cython']
    })
like image 436
Ivan Mishalkin Avatar asked Feb 14 '20 12:02

Ivan Mishalkin


People also ask

How to install tar gz file in Python?

1 First needed to unpack the tar.gz file into a folder. 2 Then before running python setup.py install had to point cmd towards the correct folder. I did this by pushd... 3 Then run python setup.py install More ...

How to fix the Python modulenotfounderror “no module named “Cython”?

The Python "ModuleNotFoundError: No module named 'Cython'" occurs when we forget to install the Cython module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install Cython command. Open your terminal in your project's root directory and install the Cython module.

Why is Pip show Cython not working?

The pip show Cython command will either state that the package is not installed or show a bunch of information about the package, including the location where the package is installed. If the package is not installed, make sure your IDE is using the correct version of Python.

How to install Seaborn from tar gz?

Basically tar.gz is just a zip file containing a setup, so what you want to do is to unzip it, cd to the place where it is downloaded and use gunzip -c seaborn-0.7.0.tar.gz | tar xf -for linux. Change dictionary into the new seaborn unzipped file and execute python setup.py install


1 Answers

Adding cython in build-system section in pyproject.toml helped me

pyproject.toml:

...
[build-system]
requires = ["poetry>=0.12", "cython"]
...
like image 109
Ivan Mishalkin Avatar answered Oct 18 '22 05:10

Ivan Mishalkin