ansys / pyansys

Delivering PyAnsys libraries as a bundle

Home Page:https://docs.pyansys.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug located while working with Jupyter Notebook to access PyAnsys specifically PyMotorCAD

Shreyas-EM opened this issue Β· comments

πŸ” Before submitting the issue

  • I have searched among the existing issues
  • I am using a Python virtual environment

🐞 Description of the bug

I tried to run a sample code in the Jupyter Notebook as below.
import os
import matplotlib.pyplot as plt
import ansys.aedt.core as pyaedt
if "QT_API" in os.environ:
os.environ["QT_API"] = "pyqt"

I am seeing the below error.
ModuleNotFoundError Traceback (most recent call last)
Input In [16], in
1 import os
3 import matplotlib.pyplot as plt

----> 5 import ansys.aedt.core as pyaedt
7 if "QT_API" in os.environ:
8 os.environ["QT_API"] = "pyqt"

ModuleNotFoundError: No module named 'ansys'

error_PyAnsys

πŸ“ Steps to reproduce

Copy paste the below code in the Jupyter notebook.
import os
import matplotlib.pyplot as plt
import ansys.aedt.core as pyaedt
if "QT_API" in os.environ:
os.environ["QT_API"] = "pyqt"

πŸ’» Which operating system are you using?

Windows

πŸ“€ Which ANSYS version are you using?

Ver.2023R1.1

🐍 Which Python version are you using?

3.7

πŸ“¦ Installed packages

ansys-api-fluent==0.3.12
ansys-api-mapdl==0.5.1
ansys-api-mechanical==0.1.0
ansys-api-meshing-prime==0.1.1
ansys-api-platform-instancemanagement==1.0.0b3
ansys-api-systemcoupling==0.1.0
ansys-corba==0.1.1
ansys-dpf-composites==0.2.0
ansys-dpf-core==0.8.1
ansys-dpf-gate==0.3.1
ansys-dpf-gatebin==0.3.1
ansys-dpf-post==0.4.0
ansys-fluent-core==0.14.0
ansys-grantami-bomanalytics==1.1.3
ansys-grantami-bomanalytics-openapi==1.0.0
ansys-grpc-dpf==0.7.1
ansys-mapdl-core==0.64.1
ansys-mapdl-reader==0.52.15
ansys-math-core==0.1.1
ansys-mechanical-core==0.8.0
ansys-meshing-prime==0.3.2
ansys-motorcad-core==0.1.3
ansys-openapi-common==1.2.1
ansys-optislang-core==0.2.1
ansys-platform-instancemanagement==1.1.1
ansys-pythonnet==3.1.0rc1
ansys-seascape==0.2.0
ansys-systemcoupling-core==0.1.3
appdirs==1.4.4
cachetools==5.3.1
certifi==2022.9.24
cffi==1.15.1
charset-normalizer==2.1.1
click==8.1.3
clr-loader==0.2.5
colorama==0.4.6
contourpy==1.1.0
cryptography==41.0.1
cycler==0.11.0
fonttools==4.40.0
google-api-core==2.11.1
google-api-python-client==2.89.0
google-auth==2.20.0
google-auth-httplib2==0.1.0
googleapis-common-protos==1.59.1
grpcio==1.54.2
grpcio-status==1.48.2
h5py==3.8.0
httplib2==0.22.0
idna==3.4
importlib-metadata==4.13.0
importlib-resources==5.12.0
kiwisolver==1.4.4
lxml==4.9.2
matplotlib==3.7.1
numpy==1.23.3
packaging==23.1
pandas==2.0.2
Pillow==9.5.0
platformdirs==3.5.3
plumbum==1.8.2
pooch==1.7.0
protobuf==3.20.3
protoc-gen-swagger==0.1.0
psutil==5.9.5
pyaedt==0.6.76
pyansys==2023.2.3
pyansys-tools-versioning==0.3.3
pyasn1==0.5.0
pyasn1-modules==0.3.0
pycparser==2.21
pyiges==0.3.0
pyparsing==3.0.9
pypiwin32==223
pyspnego==0.9.1
python-dateutil==2.8.2
pythonnet==3.0.1
pytwin==0.3.0
pytz==2023.3
pyvista==0.39.1
pywin32==304
PyYAML==6.0
requests==2.28.1
requests-negotiate-sspi==0.5.2
requests-ntlm==1.2.0
rpyc==5.3.1
rsa==4.9
scipy==1.9.1
scooby==0.7.2
six==1.16.0
tqdm==4.65.0
tzdata==2023.3
uritemplate==4.1.1
urllib3==1.26.12
vtk==9.2.6
zipp==3.15.0

Hi @Shreyas-EM thanks for opening this issue!

Your problem is with the pyaedt import statement. Try the following

import os
import matplotlib.pyplot as plt
import pyaedt as pyaedt
if "QT_API" in os.environ:
    os.environ["QT_API"] = "pyqt"

PyAEDT works a bit differently in terms of import statements to the rest of the PyAnsys libraries. You can have read more on this topic at their docs https://aedt.docs.pyansys.com/

In their user gude and examples they have running code snippets that can serve as reference to build your scripts. Have a look at them!

@maxcapodi78 @MaxJPRey I understand you might be interested in this issue, so pinging you for visibility.

Thanks @RobPasMue for providing an anwser.

Hi @Shreyas-EM ,
In the title of this issue, you mentioned that you want to to use PyMotorCad.
If so, you can find some examples here.

You don't need pyaedt to use pymotorcad. It is a different package.
You will need to do something such as:

import os

import matplotlib.pyplot as plt

import ansys.motorcad.core as pymotorcad

if "QT_API" in os.environ:
    os.environ["QT_API"] = "pyqt"

Hi @MaxJPRey ,

Thanks for the tips.. Unfortunately, running into an error as attached.

Appreciate any help on this
error_PyAnsys
please!

Thanks @RobPasMue for providing the answer for PyAedt

It seems like the packages listed above are not installed in the Python environment that is running here. [1]

This may be because Jupyter is using a different virtual environment than the one into which the packages were installed.
The documentation for switching kernels (kernels are what Jupyter calls execution environments for different programming languages, Python virtual environments, ...) can be found here: https://jupyterlab.readthedocs.io/en/stable/user/running.html
If you cannot find the appropriate kernel, maybe it needs to be added to Jupyter. The documentation for that is here: https://ipython.readthedocs.io/en/latest/install/kernel_install.html#kernels-for-different-environments

If this doesn't help, could you please provide some more information about your environment? Specifically:

  • Is this a Jupyter Notebook, or Jupyter Lab?
  • Which method did you use for installing Jupyter and the PyAnsys libraries? Manually, or using the Ansys Python Manager?
  • Could you add a screenshot of the top part of your page? Both Jupyter Notebook and Jupyter Lab should show the running kernel towards the top right of the page.

P.S.: It seems the screenshot is the same as in the original issue description (i.e., without the changes proposed by @RobPasMue). Maybe you posted the wrong screenshot?

[1] I'm not entirely sure about this, since the screenshot is showing the pyaedt issue.

Appreciate any help on this error_PyAnsys please!

Hi @Shreyas-EM - your error is related to the import statement you are performing, as I answered in #282 (comment)

Did that solve your problem?

Thanks @greschd for posting your comment, see also my previous comment. The main issue coming from the screenshot that @Shreyas-EM posted is coming from the way PyAEDT is imported. But you are totally right, the proper Python environment should be selected in any case - otherwise your packages wouldn't be available.

That's great @Shreyas-EM - thank you @greschd for your suggestion!! Closing this issue. Hope you have a nice experience with PyAnsys!