IRNAS / ppk2-api-python

Power Profiling Kit 2 unofficial python api.
http://irnas.eu
GNU General Public License v2.0
145 stars 37 forks source link

ModuleNotFoundError: No module named 'ppk2_api' #38

Closed krupis closed 4 months ago

krupis commented 10 months ago

Hello. I have been refered to this repository from the nrf devzone. Perhaps this is exactly what I am looking for (I need to be able to measure the current consumption using Python script instead of GUI).

Could you please help me understand how to get it working for the first time? I have just downloaded the repository and launched example.py script. After trying to run it, I am getting the following error:

Traceback (most recent call last):
  File "C:\Users\petrikas.lu\Downloads\ppk2-api-python-master\ppk2-api-python-master\example.py", line 10, in <module>
    from ppk2_api.ppk2_api import PPK2_API
ModuleNotFoundError: No module named 'ppk2_api'

It does not seem to find ppk2_api even though it is located at:

Downloads\ppk2-api-python-master\ppk2-api-python-master\src\ppk2_api
NejcKle commented 10 months ago

Hi @krupis, once you have cloned the repo you will have to install the python module by running pip3 install . from the root directory of the repo.

krupis commented 10 months ago

@NejcKle Thanks for a quick reply. I was not aware of this method to install required python modules. Can you explain a little bit about how it works and why do I need to install the ppk2_api module at all? Why it cannot just use the python file directly from the Downloads\ppk2-api-python-master\ppk2-api-python-master\src\ppk2_api

Anyways, I think this repository ir really cool. Its strange that nRF did not officially release something like that themselves :) I am curious how did you get all the required documentation and API to get this all together. I have tried looking for API for PPK but could really find anything.

NejcKle commented 10 months ago

@krupis the standard way of installing python packages is using the pip package manager. This module is no exception, and has been created in line with all installable python packages. This way the package is also available from the PyPi repository.

You can use the python file directly, without installing the package. The way to do this is to move the files into the directory where you will be using them and modifying the imports accordingly.

The API has been reverse engineered with the help of the python API for the first revision of the PPK, which can be found here and the nRF Connect Power Profiler app.

krupis commented 10 months ago

@NejcKle

I am aware of installing packages using pip install. I was just not aware that you can do pip install . to install all required modules .

Normally. When I install modules I just use pip install [module_name].

I am also aware that you can install all required python modules from the requirements.txt file. In the txt file you can list all the required modules and install them using pip install -r requirements.txt but I have never seen installing modules using pip install . thats why I am curious about this :)

So if I move ppk2_api from the C:\Users\petrikas.lu\Downloads\ppk2-api-python-master\ppk2-api-python-master\src\ppk2_api to the root directory of the project C:\Users\petrikas.lu\Downloads\ppk2-api-python-master\ppk2-api-python-master, then I can use this ppk2_api.py without installing the package?

wlgrd commented 10 months ago

If you don't want to do a pip install, just change the import at the top of the example to from src.ppk2_api.ppk2_api import PPK2_API

wlgrd commented 4 months ago

Closing stale issue.