Help! ModuleNotFoundError (PYTHON SDK)

Solved
ToryDavenport
Getting noticed

Help! ModuleNotFoundError (PYTHON SDK)

Hi! 

I am exploring the Python SDK and following along with the Quick Start Guide: https://developer.cisco.com/meraki/api/#/python/guides/python-sdk-quick-start


I created a test.py file here: .\My_Scripts\Meraki\Meraki_Dashboard_API\Test> python .\Test.py

The code is as follows: 

 

x_cisco_meraki_api_key = "15da0c6ffff295f16267f88f98694cf29a86ed87" # Demo Read-only API key
from meraki_dashboard_api.meraki import Meraki
meraki = Meraki(x_cisco_meraki_api_key)

orgs = meraki.organizations.get_organizations()
print(orgs)

Error shows: 

Traceback (most recent call last):
File ".\Test.py", line 2, in <module>
from meraki_dashboard_api.meraki import Meraki
ModuleNotFoundError: No module named 'meraki_dashboard_api'

 I followed the instructions within the guide, is this documentation now dated and incorrect, or is it me?

 

1 Accepted Solution
BrechtSchamp
Kind of a big deal

I'm running it from within PyCharm using the Run menu. I think that is the reason it works for me.

 

From commandline it doesn't work for me either. I think python doesn't automatically go up one folder to look for the meraki folder. If you move the testsdk.py to the Meraki_Dashboard_API folder it'll work.

View solution in original post

9 Replies 9
BrechtSchamp
Kind of a big deal

For me the import is actually different. Here's an example of what works for me:

 

from meraki.meraki import Meraki

x_cisco_meraki_api_key = '15da0c6ffff295f16267f88f98694cf29a86ed87'

client = Meraki(x_cisco_meraki_api_key)

orgs = client.organizations.get_organizations()
print(orgs)

It actually refers to Meraki class, in the meraki.py file, in the meraki folder.

 

Here's the folder structure I have:

2019-04-29 22_01_24-Meraki+Dashboard+API-Python [D__Downloads_Chrome Downloads_Meraki+Dashboard+API-.png

 

Note that my code is in testsdk.py which is in the test folder. The test folder is a sibling (that I created) of the meraki folder from the SDK download.

 

Hope that helps.

BrechtSchamp
Kind of a big deal

In this link it's actually correct:

https://developer.cisco.com/meraki/api/#/python/getting-started

 

@Melissa I think @ToryDavenport is correct, the code sample here is confusing, as the import uses another syntax from perhaps before the folder structure was changed?

 

from meraki_dashboard_api.meraki import Meraki

vs

from meraki.meraki import Meraki
ToryDavenport
Getting noticed

Hello @BrechtSchamp,

Thank you for you swift replies. 

Even using the correct folder placement and new syntax that you suggest for the import, I'm still seeing the following error: 

PS C:\Users\TORYD\OneDrive - FirstLight\My Documents\My_Scripts\Meraki\Meraki_Dashboard_API\Test> cat .\TestSDK.py
from meraki.meraki import Meraki
x_cisco_meraki_api_key = "15da0c6ffff295f16267f88f98694cf29a86ed87" # Demo Read-only API key

meraki = Meraki(x_cisco_meraki_api_key)

orgs = meraki.organizations.get_organizations()
print(orgs)
PS C:\Users\TORYD\OneDrive - FirstLight\My Documents\My_Scripts\Meraki\Meraki_Dashboard_API\Test> python .\TestSDK.py
Traceback (most recent call last):
  File ".\TestSDK.py", line 1, in <module>
    from meraki.meraki import Meraki
ModuleNotFoundError: No module named 'meraki.meraki'
PS C:\Users\TORYD\OneDrive - FirstLight\My Documents\My_Scripts\Meraki\Meraki_Dashboard_API\Test>
BrechtSchamp
Kind of a big deal

I'm running it from within PyCharm using the Run menu. I think that is the reason it works for me.

 

From commandline it doesn't work for me either. I think python doesn't automatically go up one folder to look for the meraki folder. If you move the testsdk.py to the Meraki_Dashboard_API folder it'll work.

ToryDavenport
Getting noticed

@BrechtSchamp Thank you for your help on this issue. I've accepted this as a solution. I don't typically use any text editor or IDE other than Sublime Text 3, but as you stated if I put my file in the same directory as the meraki directory it works perfectly, which, for now is fine for me. 

BrechtSchamp
Kind of a big deal

Glad to hear it's solved!

 

If you want more background info about python's algorithm to look for modules to make a more permanent solution that would make the module importable from wherever, take a look here:

https://bic-berkeley.github.io/psych-214-fall-2016/sys_path.html

and

https://bic-berkeley.github.io/psych-214-fall-2016/using_pythonpath.html

DexterLaBora
Meraki Employee
Meraki Employee

Hi, I can add some context here about the library name and location.

 

The SDK is generated based off of the new openAPI spec, and some portion of the setup instructions are also built to reflect those updates. I believe there is an issue with the doc template not indicating that you must go up one level to reference the library. I wrote the Getting Started guides, which should include the correct procedure as I tested the SDK. This is also true for the Node SDK. The naming of the SDK, classes, methods, etc were also heavily in flux at the same time it was being documented, so thanks for highlighting any discrepancies.

 

In the near future, we will be publishing the SDKs into the PIP and NPM registries, which will simplify the install process. 

 

Please share your feedback with these newly minted SDKs. Our community is instrumental in the success of the API and your input is taken to heart. 

dillonator
Conversationalist

Not sure if this is the right place to post, but I had a couple of python scripts written based off the previous library (before the SDK came out) that broke recently. I updated the library and that seemed to fix the issues (see code below).

 

I looked at the SDK briefly but since it's not published into PIP and/or NPM, it's been very difficult to get started. (I'm not a programmer by any means. Just wrote some scripts to help me quickly deploy sites/networks.)

 

pip install meraki --upgrade
ToryDavenport
Getting noticed

I was JUST about to work on a script using that library. I will ensure that I update first. Thanks for sharing!

Get notified when there are additional replies to this discussion.