Skip to content

Navigation Menu

Sign in
Sign up

Issue with PyAnsys Installation: ModuleNotFoundError #569

Answered by RobPasMue
t0xine asked this question in Q&A
Discussion options

Dear all,

I hope this message finds you well. I am reaching out to seek assistance with an issue I encountered while attempting to use PyAnsys.

I'm working with Python on VS code.

Upon installing PyAnsys via pip and attempting to run a script, I encountered the following error message:

ModuleNotFoundError: No module named 'ansys.geometry'; 'ansys' is not a package

I have already taken the following steps to troubleshoot the issue:

 * Checked the installation of PyAnsys to ensure it was successful.
 * Ensured that all dependencies required by PyAnsys are installed.
 * Confirmed that I am using the correct Python interpreter and environment.
 * Attempted to isolate the issue by running the script in a virtual environment.

Despite these efforts, I am still unable to resolve the error. I would greatly appreciate any guidance or assistance you can provide to help me resolve this issue and successfully utilize PyAnsys for my project.

The package ansys is in the same directory as numpy:

C:\Users\x\AppData\Local\Programs\Python\Python312\Lib\site-packages\ansys\geometry\core

C:\Users\x\AppData\Local\Programs\Python\Python312\Lib\site-packages\numpy

VS code has no problem running numpy but cannot run ansys.

import ansys
print(dir(ansys))

output:

['builtins', 'cached', 'doc', 'file', 'loader', 'name', 'package', 'spec', 'ansys']

If you require any additional information or logs to assist with troubleshooting, please don't hesitate to ask. Your help in resolving this matter would be greatly appreciated.

Thank you very much for your time and support.

Best regards,

Julien

You must be logged in to vote

Hmm...

I'm worried about the "vs code" folder. Spaces are typically a problem... Can we do as follows? You will just need to copy paste my commands on a terminal.

  1. Open a new PowerShell terminal (fresh, not inside VSCode)
  2. Create a folder in documents called pygeometry_test: mkdir C:\Users\lac\Documents\pygeometry_test
  3. Move to this folder: cd C:\Users\lac\Documents\pygeometry_test
  4. Create a virtual environment: python -m venv .venv
  5. Activate the venv: .venv\Scripts\activate
  6. Install pyansys: python -m pip install pyansys
  7. Open a Python terminal: python
  8. Run the following:
from ansys.geometry.core import __version__
print(__version__)

Please, follow each command step by step. If you encounter ...

Replies: 3 comments 12 replies

Comment options

Hi @t0xine!

Thanks for reaching out, let me try to support you in your request. Please, verify with me the following:

  1. Is the pyansys package installed?
    If so, running the following command on PowerShell/CMD should give you a similar output to mine:
>>> pip freeze
...
pyansys==???????
...

If the above is not true, please run pip install pyansys

  1. Which version of pyansys is installed?
    This would be the ??????? in the previous output.

  2. What is the output of running the following code snippet in your Python terminal?

import ansys.geometry.core as pygeometry
print(pygeometry.__version__)
You must be logged in to vote
2 replies
Comment options

Hi,
Thank you for the answer!
From pip freeze I can see all the sub-package of pyansys (ansys-geometry-core, ansys-mechanical-core...) and pyansys==2024年1月8日
image

Comment options

I believe your IDE (VSCode if I am not mistaken) is getting the wrong Python interpreter. Do you have your dependencies installed in a virtual environment? If so, you should make use of that specific interpreter. One thing you can try is:

  1. Activate your virtual environment (on windows: .\.venv\Scripts\activate
  2. Run your script right after: python ansys.py
Comment options

Here is what I have done (everything on the Command Prompt):

  • Create a venv environment (py -m venv myenv)

  • Activate it (myenv\Scripts\activate)

  • Run ansys.py
    (Traceback (most recent call last):
    File "C:\Users\x\Documents\vs code\ansys.py", line 1, in
    import ansys.geometry.core as pygeometry
    File "C:\Users\x\Documents\vs code\ansys.py", line 1, in
    import ansys.geometry.core as pygeometry
    ModuleNotFoundError: No module named 'ansys.geometry'; 'ansys' is not a package)

  • Download pyansys on the venv (pip install pyansys)

  • Check for the version (pyansys==2024年1月8日)

  • Run again (same output as previously)

You must be logged in to vote
3 replies
Comment options

How are you running the script? Through your IDE or through the command line?

Comment options

I try both

Comment options

Make sure your IDE is pointing towards your virtual environment:

image

In my case I am using the Python interpreter in my virtual environment.

Another option is to do the following...

  1. Go to your ansys.py folder on the terminal
  2. python -m venv .venv
  3. .venv\Scripts\activate
  4. python -m pip install pyansys
  5. python ansys.py
Comment options

image
image
image
Numpy is working perfectly but not PyAnsys

You must be logged in to vote
7 replies
Comment options

This is very weird, first time I see it...

Can you verify that .venv2\Lib\site-packages\ansys exists?

Comment options

C:\Users\lac\Documents\vs code.venv2\Lib\site-packages\ansys\geometry\core
and all other sub-package

Comment options

Hmm...

I'm worried about the "vs code" folder. Spaces are typically a problem... Can we do as follows? You will just need to copy paste my commands on a terminal.

  1. Open a new PowerShell terminal (fresh, not inside VSCode)
  2. Create a folder in documents called pygeometry_test: mkdir C:\Users\lac\Documents\pygeometry_test
  3. Move to this folder: cd C:\Users\lac\Documents\pygeometry_test
  4. Create a virtual environment: python -m venv .venv
  5. Activate the venv: .venv\Scripts\activate
  6. Install pyansys: python -m pip install pyansys
  7. Open a Python terminal: python
  8. Run the following:
from ansys.geometry.core import __version__
print(__version__)

Please, follow each command step by step. If you encounter any problems in the way let me know

Answer selected by RobPasMue
Comment options

image
image

Oh great it's working!

Comment options

Cool! Like I said... I think the blank spaces are playing with your Python interpreter somehow. What you can try and do now is to open VSCode in this folder specifically. Let me know how it goes!

Comment options

It seems that everything is working properly. Thanks you a lot for your much needed help.
Best!

Comment options

Anytime! Glad I was able to help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /