0

In github there are four py Data which I put on my PyCharm. When I run main.py I get this message:

/Users/Armut/Desktop/High_D/Coursera/bin/python /Users/Armut/Desktop/High_D/main.py
Traceback (most recent call last):
  File "/Users/Armut/Desktop/High_D/main.py", line 6, in <module>
    from data_management.read_csv import *
ModuleNotFoundError: No module named 'data_management'

Here is a screenshots:

enter image description here

Can someone help, what I am doing wrong or how can I fix it?

EDIT (Put folders):

/Users/Armut/Desktop/High_D/Coursera/bin/python /Users/Armut/Desktop/High_D/main.py
WARNING:root:Failed to import geometry msgs in rigid_transformations.py.
WARNING:root:Failed to import ros dependencies in rigid_transforms.py
WARNING:root:autolab_core not installed as catkin package, RigidTransform ros methods will be unavailable
Traceback (most recent call last):
  File "/Users/Armut/Desktop/High_D/main.py", line 7, in <module>
    from visualization.visualize_frame import VisualizationPlot
ModuleNotFoundError: No module named 'visualization.visualize_frame'

enter image description here

EDIT:

/Users/Armut/Desktop/High_D/Coursera/bin/python /Users/Armut/Desktop/High_D/src/main.py
Traceback (most recent call last):
  File "/Users/Armut/Desktop/High_D/src/main.py", line 7, in <module>
    from src.visualization.visualize_frame import VisualizationPlot
  File "/Users/Armut/Desktop/High_D/src/visualization/visualize_frame.py", line 10, in <module>
    from utils.plot_utils import DiscreteSlider
ModuleNotFoundError: No module named 'utils.plot_utils'

enter image description here

Edit (No errors, but I just get a blank picture):

enter image description here

Edit (I installed matplotlib 3.0.3 and got this): The issue here is, that it is just a picture. If you can see there are buttons like "next". I should be able to click it so I can track it. But how does it work?

enter image description here

Yokanishaa
  • 75
  • 5

1 Answers1

1

Do the following


from read_csv import *
import visualize_frame as vf

The reason why it was not working for you is because you were importing files that dont exist on your system. When you do from data_management.read_csv import *, what you are telling the Python interpreter to do is to search for a folder called data_management inside you're Coursera folder and get everything from read_csv.py.

This is the same case with visualize_frame. Since you have a flat directory structure, you dont need the folder names. You can directly import the .py files as is.

Another thing to note here is that I personally wouldn't do from read_csv import * because I will be flooding my namespace with a lot of things I probably wont use. I would rather use import read_csv as any_alias_you_like. This way I only fill my namespace with what I want by doing the following

x = any_alias_you_like.function_call()

The reason why I didn't do this with the main code solution is because I am not sure where all you are using read_csv functions and classes in your code and if that is not accounted for by prefxing the alias name properly, you will run into a multiple errors. So my advice is to identify all the funcutions/classes that you are using in read_csv.py and prefix them properly with an alias.

I also used the import statement for the visualize_frame differently. This is because, when you do a from import..., you are only partially initializing the module. However, a proper import visualize_frame will ensure that your entire module is initialized in one call and you can use everything it offers by simply prefixing the alias.

Read about the difference between from import and import... here.

Read about how Python searches for libraries here.

Lihka_nonem
  • 352
  • 1
  • 8
  • Thanks a lot. I just put folders in it because in github there are also folders. I do not really understand the code... I just want to try to run it because I need it. Here is the github Link: https://github.com/RobertKrajewski/highD-dataset/tree/master/Python/src – Yokanishaa May 11 '22 at 09:58
  • 1
    Ok, so, you will have to change your directory structure. Create a new folder called `src` inside the `HighD` folder and copy the folders you just created for `data_management`, `utils` and `visualize` into it. Also copy the `main.py` file and paste it into `src`. Now when you open `src`, you should see 3 folders and a `.py` file. After that, go back one step to the `HighD` folder, and create another folder called `data`. This means that your `HighD` folder will now have 3 folders called `Coursera`, `data` and `src`. Put your `.csv` inside the `data` folder and then run `main.py` – Lihka_nonem May 11 '22 at 10:11
  • I did but unfortunately there is the next error.. – Yokanishaa May 11 '22 at 10:23
  • 1
    Ok. Inside the `visualize_frame.py` file, change `from utils.plot_utils import DiscreteSlider` to `from src.utils.plot_utils import DiscreteSlider` – Lihka_nonem May 11 '22 at 10:29
  • Thanks a lot, you help me so much. It is not over but I get a picture at least. https://github.com/RobertKrajewski/highD-dataset/issues/11 Here is someone that had the same issue like me. If you scroll down she said, that it works for her when she "created a new virtual env with the following packages:..." How can I do that? Is there also a folder which I need to change? – Yokanishaa May 11 '22 at 11:02
  • It's my pleasure to help :) Do not manually create a folder. Goto this [link](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/). Follow the steps in this to create a virtual environment for your project. Make sure your `env` folder is in `./HighD` and not `./HighD/src`. After this copy all the dependencies the lady on GitHub provided and name the file `requirements.txt`. Keep the `requirements.txt` file inside `HighD`. After this goto the part of the document linked above that says `Using requirements files` and follow the instructions provided. – Lihka_nonem May 11 '22 at 11:46
  • Things to note, if you accidentally created the `env` folder in `./HighD/src`, do not cut and paste it in `./HighD`. Delete the `env` folder and recreate it from scratch with the proper path. Follow this [link](https://www.lifewire.com/open-command-prompt-in-a-folder-5185505) and goto the section titled `How Do I Open a Terminal Window in a Folder?` for setting your cmd prompt to the path to the root folder correctly. – Lihka_nonem May 11 '22 at 11:48
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/244659/discussion-between-lihka-nonem-and-yokanishaa). – Lihka_nonem May 11 '22 at 11:56