mojo
mojo copied to clipboard
[BUG]: Error importing numpy: you should not try to import numpy from its source directory;
Bug description
Steps to reproduce
$ mojo
Welcome to Mojo! 🔥
Expressions are delimited by a blank line.
Type `:quit` to exit the REPL and `:mojo help` for further assistance.
1> from python import Python
2. let np = Python.import_module("numpy")
3. let array = np.array([1, 2, 3])
4. print(array)
5.
Error: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python interpreter from there.
5>
System information
- What OS did you do install Mojo on ?
macOS 14.3.1
- Provide version information for Mojo by pasting the output of `mojo -v`
mojo 0.7.1 (af002202)
- Provide Modular CLI version by pasting the output of `modular -v`
modular 0.5.0 (47924ae4)
Same issue here on x86_64 ubuntu 23.10 :(
python_lib = /home/catalpa/miniforge3/envs/a3/lib/libpython3.12.so
@catalpaaa Removing Mojo completely and then reinstalling it will fix this issue.
I have the same issue on a MacOS Ventura 13.4
. This error persists even after completely removing mojo and modular, and reinstalling everything.
Output of
mojo -v
mojo 24.1.0 (55ec12d6)
Output of
modular -v
modular 0.5.1 (1b608e3d)
I created a conda
environment using
conda create -yn mojo python=3.11
In my bash_profile
, the following paths are set:
export MODULAR_HOME="$HOME/.modular"
export PATH="$MODULAR_HOME/pkg/packages.modular.com_mojo/bin:$PATH"
export MOJO_PYTHON_LIBRARY="$HOME/miniconda3/envs/mojo/lib/libpython3.11.dylib"
The easiest way for me to reproduce this error is to run the RayTracing.ipynb
under the examples directory in this repo. Calling the render
function throws:
Error: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python interpreter from there.
I have the same issue on a
MacOS Ventura 13.4
. This error persists even after completely removing mojo and modular, and reinstalling everything.Output of
mojo -v
mojo 24.1.0 (55ec12d6)Output of
modular -v
modular 0.5.1 (1b608e3d)I created a
conda
environment usingconda create -yn mojo python=3.11
In my
bash_profile
, the following paths are set:export MODULAR_HOME="$HOME/.modular" export PATH="$MODULAR_HOME/pkg/packages.modular.com_mojo/bin:$PATH" export MOJO_PYTHON_LIBRARY="$HOME/miniconda3/envs/mojo/lib/libpython3.11.dylib"
The easiest way for me to reproduce this error is to run the
RayTracing.ipynb
under the examples directory in this repo. Calling therender
function throws:Error: Error importing numpy: you should not try to import numpy from its source directory; please exit the numpy source tree, and relaunch your python interpreter from there.
I figured out that I am able to execute the ray tracing code as a stand-alone mojo script using iterm
but NOT vscode's built-in terminal. This is will be my work around for the time being.
same issue for me, after updateing mojo I can't import numpy anymore. I can't event import from iTerm.
numpy version = 1.23 mojo version = 24.1.0 modular version = 0.5.2 conda version = 23.11.0 macOs = 14.2.1
system path:
'/opt/homebrew/opt/[email protected]/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages',
'~/opt/miniconda3/envs/env_name/lib/python310.zip',
'~/opt/miniconda3/envs/env_name/lib/python3.10',
'~/opt/miniconda3/envs/env_name/lib/python3.10/lib-dynload',
'~/opt/miniconda3/envs/env_name/lib/python3.10/site-packages'
For me it was caused by a mismatch between the system python v3.10 and my virtual environment python v3.11. If I set MOJO_PYTHON_LIBRARY
it worked just fine. You'll need to hunt down your python libraries for your system. For me it was:
export MOJO_PYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.11.so.1.0
For me it was caused by a mismatch between the system python v3.10 and my virtual environment python v3.11. If I set
MOJO_PYTHON_LIBRARY
it worked just fine. You'll need to hunt down your python libraries for your system.
Indeed I manage to fix it after updating my conda environment to python 3.12 as it matches the mojo python_lib
version.