If I compile a file with import requests, will the requests also be compiled and become one file?

9 views
Skip to first unread message

gee bobbb

unread,
Nov 22, 2022, 12:55:00 AM11/22/22
to cython-users
I am a beginner.
If I run "python setup.py build_ext --inplace" with the following two files
If I run python setup.py build_ext --inplace on the following two files, will the imported requests module also be compiled and become one file?
Also, I imported the compiled file into another program, but it does not recognize the requests.
Why is this?

(test.pyx)
import requests
.............
.............

(setup.py)
from setuptools import setup
Build import cythonize
setup(
    ext_modules = cythonize('test_.pyx')
)

Translated with www.DeepL.com/Translator (free version)

D Woods

unread,
Nov 22, 2022, 1:00:56 PM11/22/22
to cython-users
On 21/11/2022 21:59, gee bobbb wrote:
> If I run python setup.py build_ext --inplace on the following two files, will the imported requests module also be compiled and become one file?

No.


> Also, I imported the compiled file into another program, but it does not recognize the requests.
> Why is this?

It's not clear what you've done here - have you tried to create an executable or a module? If you've created an executable then you need to point it to the Python path (i.e. where it can find requests). Use PySys_SetPath or similar (https://docs.python.org/3.8/c-api/sys.html#c.PySys_SetPath)

If you're just looking to create a self-contained executable then there are dedicated tools that are much more suitable than Cython, like PyInstaller, cx_freeze, nuitka.


Amir Ramezani

unread,
Nov 22, 2022, 4:41:33 PM11/22/22
to cython...@googlegroups.com
Hi,
the imported modules will be imported like normal python modules, and
no compilation will be done on them and they should be present for
your module to run

۱۴۰۱-۰۹-۰۱ ۱:۲۹ ‎+۰۳:۳۰ گرینویچ, gee bobbb <au99x...@gmail.com>:
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "cython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cython-users...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/cython-users/301b05ac-cd3b-415d-9da2-9edff92accebn%40googlegroups.com.
>
Reply all
Reply to author
Forward
0 new messages