Open zhugw opened 2 years ago
I am fine with using taichi in Jupyter environments inside VSCode Jupyterlab and also Jupyter notebook. Maybe you can try to use Jupyter lab with anaconda?
Maybe it's pycharm's problem, I will submit bug to pycharm
Your stack trace tries to import bpy
which is the Python interface of Blender. I would recommend to double check your Python environment and see whether it involves Blender Python at any point.
"double check your Python environment and see whether it involves Blender Python at any point." how to check like this
pip list | grep -i Blender
And run the same code in Python console is ok
(venv) ➜ 3i git:(master) ✗ python
Python 3.8.2 (default, Apr 8 2021, 23:19:18)
[Clang 12.0.5 (clang-1205.0.22.9)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import taichi as ti
[Taichi] version 1.1.2, llvm 10.0.0, commit f25cf4a2, osx, python 3.8.2
>>> ti.init()
[Taichi] Starting on arch=x64
>>> @ti.func
... def is_prime2(n: int):
... result = True
... for k in range(2, int(n ** 0.5) + 1):
... if n % k == 0:
... result = False
... break
... return result
>>> @ti.kernel
... def count_primes2(n: int) -> int:
... count = 0
... for k in range(2, n):
... if is_prime2(k):
... count += 1
... return count
...
>>> print(count_primes2(1000000))
78498
but run it in Pycharm jupyter notebook failed
I was having the same issue, but I've found a workaround. Try commenting %%time
in your code or moving it to a cell, where you call count_primes2
.
@CakeOrRiot when removed %%time
it's ok. Amazing!
Hope could use taichi in jupyter notebook directly, now run sample code in cell failed with below exception