-
Notifications
You must be signed in to change notification settings - Fork 130
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
All reactions
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.
- Open a new PowerShell terminal (fresh, not inside VSCode)
- Create a folder in documents called pygeometry_test:
mkdir C:\Users\lac\Documents\pygeometry_test - Move to this folder:
cd C:\Users\lac\Documents\pygeometry_test - Create a virtual environment:
python -m venv .venv - Activate the venv:
.venv\Scripts\activate - Install pyansys:
python -m pip install pyansys - Open a Python terminal:
python - 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
Hi @t0xine!
Thanks for reaching out, let me try to support you in your request. Please, verify with me the following:
- Is the
pyansyspackage 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
-
Which version of
pyansysis installed?
This would be the???????in the previous output. -
What is the output of running the following code snippet in your Python terminal?
import ansys.geometry.core as pygeometry print(pygeometry.__version__)
All reactions
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
All reactions
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:
- Activate your virtual environment (on windows:
.\.venv\Scripts\activate - Run your script right after:
python ansys.py
All reactions
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)
All reactions
How are you running the script? Through your IDE or through the command line?
All reactions
I try both
All reactions
Make sure your IDE is pointing towards your virtual environment:
In my case I am using the Python interpreter in my virtual environment.
Another option is to do the following...
- Go to your ansys.py folder on the terminal
python -m venv .venv.venv\Scripts\activatepython -m pip install pyansyspython ansys.py
All reactions
This is very weird, first time I see it...
Can you verify that .venv2\Lib\site-packages\ansys exists?
All reactions
C:\Users\lac\Documents\vs code.venv2\Lib\site-packages\ansys\geometry\core
and all other sub-package
All reactions
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.
- Open a new PowerShell terminal (fresh, not inside VSCode)
- Create a folder in documents called pygeometry_test:
mkdir C:\Users\lac\Documents\pygeometry_test - Move to this folder:
cd C:\Users\lac\Documents\pygeometry_test - Create a virtual environment:
python -m venv .venv - Activate the venv:
.venv\Scripts\activate - Install pyansys:
python -m pip install pyansys - Open a Python terminal:
python - 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
All reactions
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!
All reactions
It seems that everything is working properly. Thanks you a lot for your much needed help.
Best!
All reactions
-
❤️ 1
Anytime! Glad I was able to help!