ampl / amplpy

Python API for AMPL

Home Page:https://amplpy.ampl.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ModuleNotFoundError: No module named '_amplpython'

fernandafalves opened this issue · comments

When I try to run the "import amplpy" line I get the error "ModuleNotFoundError: No module named '_amplpython". Complete output:

Traceback (most recent call last):
  File "c:/Users/ferna/Drive/Framework/Script.py", line 1, in <module>
    import amplpy
  File "c:\Users\ferna\Drive\Framework\amplpy\__init__.py", line 3, in <module>
    from .outputhandler import OutputHandler, Kind
  File "c:\Users\ferna\Drive\Framework\amplpy\outputhandler.py", line 6, in <module>
    from . import amplpython
  File "c:\Users\ferna\Drive\Framework\amplpy\amplpython\__init__.py", line 22, in <module>
    from amplpython import *
  File "c:\Users\ferna\Drive\Framework\amplpy\amplpython\cppinterface\amplpython.py", line 15, in <module>
    from _amplpython import *
ModuleNotFoundError: No module named '_amplpython'

Hi Fernanda,

Thanks for reporting this issue. Which python version do you have and how did you install amplpy (i.e., pip, conda, local build)?

I'm using Python 3.8.6 64-bit. I installed amplpy using pip and conda, but neither worked.

Could you please run python -m pip install amplpy --upgrade, followed by python -m amplpy.tests, and send us the output of both commands?

The output of the first command:
Requirement already satisfied: amplpy in c:\users\ferna\anaconda3\lib\site-packages (0.7.0)
Requirement already satisfied: future>=0.15.0 in c:\users\ferna\anaconda3\lib\site-packages (from amplpy) (0.18.2)

The output of the second command:
[('_s', <amplpy.set.Set object at 0x0000024628FA0C70>)]
..Error:
line 1 offset 2
syntax error
.1 = 1

...Display: |1 = 1
2 = 2
3 = 3

|
<class 'amplpy.exceptions.AMPLException'>
Warning: X is not defined
<class 'amplpy.exceptions.AMPLException'>
Error: syntax error
..set A := 1 2 3 4 5 6 7 8 9 10;

.['BEEF', 'CHK', 'FISH', 'HAM', 'MCH', 'MTL', 'SPG', 'TUR']
['BEEF', 2.0, 10.0, 3.19]
['CHK', 2.0, 10.0, 2.59]
['FISH', 2.0, 10.0, 2.29]
['HAM', 2.0, 10.0, 2.89]
['MCH', 2.0, 10.0, 1.89]
['MTL', 2.0, 10.0, 1.99]
['SPG', 2.0, 10.0, 1.99]
['TUR', 2.0, 10.0, 2.49]
A
A
A
A
A
A
A
A
B1
B1
B1
B1
B1
B1
B1
B1
B2
B2
B2
B2
B2
B2
B2
B2
C
C
C
C
C
C
C
C
CAL
CAL
CAL
CAL
CAL
CAL
CAL
CAL
NA
NA
NA
NA
NA
NA
NA
NA
..........x = 3.14159

................

Ran 35 tests in 8.338s

OK

The output shows that amplpy is installed at c:\users\ferna\anaconda3\lib\site-packages and working (i.e., it is passing the tests).

In the error message you sent in the initial message amplpy is being loaded from "c:\Users\ferna\Drive\Framework\amplpy", which may just be the source version of amplpy. Could you please rename that folder to something else to avoid it being loaded by mistake?

In fact, I copied the folder from the directory where the amplpy is installed (c:\users\ferna\anaconda3\lib\site-packages) because when I don't have the amplpy folder in the same directory as the file I'm trying to run, the message "ModuleNotFoundError: No module named 'amplpy'" appears.

Hi Fernanda, in that case it looks like you have multiple python versions installed and the one in which is want to use amplpy is not the one where you installed it. How are you running the script that fails with "ModuleNotFoundError: No module named 'amplpy'"?

I'm running using:
"C:/Users/ferna/AppData/Local/Programs/Python/Python38/python.exe c:/Users/ferna/Drive/Framework/Script.py"

Could you please try installing amplpy with: C:/Users/ferna/AppData/Local/Programs/Python/Python38/python.exe -m pip install amplpy --upgrade

I installed amplpy using this command line and it worked perfectly. I tested running the Script now, with the line "import amplpy" and no errors were reported.

Thanks for the help!!