Importing Modules
ramondebruyn opened this issue · 4 comments
Hi again!
I've been experimenting the current implementation some when I try to import specific modules I get the following error:
Fatal error: 'try!' expression unexpectedly raised an error: Python exception: No module named 'numpy': file PythonKit/Python.swift, line 674
2021-02-28 22:10:32.622406-0500 PythonPlayground[76992:6218680] Fatal error: 'try!' expression unexpectedly raised an error: Python exception: No module named 'numpy': file PythonKit/Python.swift, line 674
(lldb)
This error resulted adding this line below line 41 of the ContentView file (let sys = Python.import("sys"):
let np = Python.import("numpy")
Do I need to need to have the modules pre-installed in a specific location (on my hard drive or in the app bundle) for me to be able to import them, and how would I go about doing that?
Thanks again!
See https://github.com/kewlbear/NumPy-iOS. NumPy is not a pure Python package. You need to compile non-Python sources and link it with your app to use Python part of NumPy.
Thanks for the response @kewlbear. I hear you regarding NumPy specifically. That being said, I've tried to import other packages like Pandas and Gensim, and get the same issue. Would the same method you mentioned above work for modules such as these, or is your above solution only applicable to NumPy in specific?
If a python package uses C extensions, similar steps need to be done. For pandas, they state that it uses C extension here: https://pandas.pydata.org/docs/development/contributing.html#installing-a-c-compiler.
@kewlbear Thanks for the info. I'll look dig deeper into that.