It looks like you're new here. If you want to get involved, click one of these buttons!
Hi,
I recently tried to rerun some of my old codes (maybe from a year ago), and surprisingly, they didn’t compile! In some of the codes, I imported the numpy library, but Klayout returned this error:
ImportError: 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.
Did Klayout change anything that prevents numpy from being imported?
My Klayout version is 0.28.13.
To add to this problem, this issue appear only in Windows version and not in Ubuntu version.
Comments
Hi @ashkan,
I am regularly upgrading the build environment as including new components forces me to do so. This means that also numpy versions change.
In 0.28.12 numpy was 1.21.0. In 0.28.13, numpy is 1.26.1.
I am not really familiar with numpy and I have no idea what this message means. But plain "import numpy" on the console works, so I don't think there is a general issue. Maybe you did set a sys.path that numpy does not like? Or maybe the version makes a difference?
Regards,
Matthias
I'm having the same problem in both the
Windows binary distribution
and theMINGW64 source build
.1. Comparison of Different Builds






2. Initial Survey
https://github.com/numpy/numpy/issues/24965#issuecomment-1772872708
Despite the above comments,

3. Reinstallation
I uninstalled then reinstalled numpy and the packages that depend on it, but the problem remained unchanged.
4. Values of sys.path



I also checked the
sys.path
and found that the source build was weird.5. KLayout 0.28.13 on different MacOS

No problems.
Best regards,
Kazzz-S
6. Values of sys.path (again)
I edited the contents of

bin-release/.python-paths.txt
and got the expected path settings.7. Further investigation(1)
The original exception message seems inappropriate, so I have modified



numpy/__init__.py
and got different messages.To be continued...
Hi @sekigawa,
thanks for these investigations.
I could not reproduce the problems myself yet, but I will try with different machines. The ones I tested had numpy installed on them.
I actually did not change anything between 0.28.12 and 0.28.13 except adding libgit2 and upgrading to latest MSYS. I did not a few times before and never ran in trouble with numpy.
Matthias
I could reproduce the problem after wiping my system entirely. So I am suspecting some essential DLL is missing.
sys.path looks normal to me.
I will try to find the missing pieces ...
Matthias
Looks like for some reason the essential DLLs are missing in the installation. I assume the packaging script has some trouble with the new MSYS version. I will try to fix that and provide new Windows packages.
Matthias
I stand corrected: the DLLs are now called ".pyd" - so they are there. It's a different problem then.
Matthias
Okay, found the issue: some DLLs that the .pyd depend on are not installed. I got it working by copying
to the same place than "_multiarray_umath.cp311-mingw_x86_64.pyd".
The reason for the missing DLLs is that the build script collects dependent DLLs, but only analyzes ".dll" files, not ".pyd".
I think that is easy to fix. I'll provide a new Windows installer.
Matthias
I have created a ticket for this here: https://github.com/KLayout/klayout/issues/1553
Matthias
Hi @Matthias,
Thanks for your effort
8. Further investigation(2)

After manually copying the four DLLs (in the source build env), I can import
numpy
normally.I hope the other cases have the same root cause.
Best regards,
Kazzz-S
I fixed the deployment script and uploaded new installers. Version is still 0.28.13 because only DLLs got added. Please re-install using the Windows installers from https://www.klayout.de/build.html.
I can import numpy, scipy, pandas, matplotlib and other packages now.
Thanks for these investigations.
Matthias
Hi @Matthias,
Thanks for the quick fix.


I've tested the new Windows ZIP package and found it OK!
Kazzz-S
Very good. I'm happy to hear it works on your side too!
Best regards,
Matthias
@Matthias It works on my device too.
Thanks.
@Matthias I'd like to report a possible bug in KLayout 0.28.13. I am not sure if it is related to my version, but I tried it on version 0.28.5 and it works fine. The problem occurs when I try to move an object with the Movements setting in Diagonal mode. I cannot move the object to any angle between 90 and 180 degrees or between 270 and 360 degrees. If I try to do so, the object’s movement will be mirrored on the X-axis. Could you please check on this issue and let me know if there is a solution?
Edit1:
Another issue that I have noticed is that when I try to move an array of objects by clicking on the desired location, they will suddenly jump to a different place.
Edit2:
I have found another strange behavior when I use a Pcell and then flatten it. If I modify anything on that specific Pcell in its layout, all other Pcells also change accordingly!
Please use the issue tracker on GitHub for bug reports (https://github.com/KLayout/klayout). This discussion is about a different topic.
But I guess you're not facing a bug. Instead you are editing objects inside the hierarchy and that will make all other places, where this object is used, change as well. This is the magic of hierarchical layout.
Turn on "Select Top Level Objects" in the "View" menu, so you can only select objects from the top cell. This will avoid these issues, but you have to enter subcells if you want to do edits there. "Descend in hierarchy" (Ctrl+D) is a way to do so and it is comparable with "Edit in Place" in Cadence.
Matthias
@Matthias I just installed ST-klayout-0.29.12-macOS-Sequoia-1-qt5MP-RsysPsys in my Mac running Sequoia 15.3.2. I have no problem loading numpy in Terminal. When I try to load numpy in the KLayout macro environment, I get an error importing numpy. The error lead me to this forum post. Can you help?

Thanks, Long
Hi @Long,
Since you can successfully start the application, you installed the Apple Command Line Tools correctly.
However, some optional Python packages, including
numpy
, are not correctly installed.I guess you have installed another Python3 through Anaconda3 (most likely), Homebrew, or MacPorts.
The Python3 you are running in your Terminal does not match the one KLayout uses.
See the command executions and their outputs below for details.
How to use pip to install a new package using the python3 command above...
Use the full path if required.
Sequoia1{kazzz-s} temp (1)%
[sudo] python3 -m pip install a_new_module
To newly install
numpy
...Sequoia1{kazzz-s} temp (2)%
[sudo] python3 -m pip install numpy
In my case...
The test CSV file
sampleCSV.csv
is not included in the DMG files.You can use any (UTF-8 encoded and "," separated) one.
Good luck.
Kazzz-S
Hi @Long,
The actual cause may be different from what I imagined initially.
Please let me know the results by comparing them with my environment.
Cont.
Where does @rpath point?
Re-installation of the numpy package
I uninstalled the existing numpy package with
sudo
and reinstalled it to a different directory.It still works as expected.
Hi @Long,
I tried to use a virtual environment as follows.
This also works fine.
Setup the virtual environment
Use the virtual environment in KLayout
Automator.app
application, create a launch service app as follows.KLAYOUT_PYTHONPATH
environment variable before invoking the KLayout application bundle.Check your sys.path


Hi @sekigawa, I thought about trying out the HW-klayout-0.29.12-macOS-Sequoia-1-qt5MP-RsysPhb311.dmg on my way to work. After installing it and then numpy (according to the ReadMeFirst), I was able to load it! Then I logged onto this forum to find your excellent guide to setup a virtual environment. Is this effectively what the HW version does?
I developed a package of macros and PCells (https://github.com/UUhy/LTK, https://uhnf.egr.uh.edu/nanofabrication/lithography/klayout/digitize-graph/) a few years ago and uploaded it to salt. It was difficult for me to help whenever someone installs my package and it doesn't work because I just don't know how application find dependencies it needs on other folk's computer. Perhaps telling them to install the HW version is the solution?
Thank you so much Kazzz-S,
Long
Hi @Long,
As you mentioned, the steps explained in
Homebrew-User-ReadMe First.txt
(HW-*.dmg) and the ones regarding the virtual environment setup (described above) are effectively equivalent.Academic people originally conceived the idea for HW (all-in-one). I understand they wanted to make KLayout and its extensions easy for students unfamiliar with software development environment administration.
However, if you can set up a virtual environment as described above (I don't think it's that difficult), I strongly recommend it.
We must create a launch service for macOS, but this is not difficult either.
Using a virtual environment is clean, safe, and flexible. It is beneficial for projects that require trial and error compared to installing different packages globally.
Also, Homebrew's Python 3.12 and later prohibits installing packages globally via pip.
For this reason,
HW-klayout-0.29.12-macOS-Sequoia-1-qt5MP-RsysPhb311.dmg
embeds Python 3.11.On the other hand,
LW-klayout-0.29.12-macOS-Sequoia-1-qt6Brew-Rhb34Phb312.dmg
is built to use Homebrew's newer Python 3.12 and a virtual environment.Kazzz-S