[Tutor] ImportError: attempted relative import with no known parent package

Peter Otten __peter__ at web.de
Tue Jul 13 04:43:13 EDT 2021


On 13/07/2021 06:26, adityakarthik9 at gmail.com wrote:
>     Hi.
> 
> 
> 
>     I am trying to execute a dump file using a .py file.
> 
> 
> 
>     I am using ubuntu for my projects.
> 
> 
> 
>     The command I give in the ubuntu terminal is :
> 
> 
> 
>     python3 main.py file.dump
> 
> 
> 
>     When I type this command, I get an error stating that:
> 
> 
> 
>     File "main.py", line 3, in
> 
>   from .Histogram import Histogram
> 
> 
> 
>     ImportError: attempted relative import with no known parent package
> 
> 
> 
>     I am trying to plot histogram for my dump file. So the output of this
>     command should give me the frequency with which an assembly instruction is
>     repeated in the dump file.
> 
>     I am using the program from the following link to get the results.
> 
>     https://github.com/riscv-newop/riscv-newop/tree/master/rvnewop
> 
>     From my understanding, the error is occurring due to some directory
>     mis-match but I made sure that all the files are in the same directory.
> 
>     I am not sure where I am going wrong.

If you installed the program with pip as suggested here 
https://github.com/riscv-newop/riscv-newop

python3 -m rvnewop path/to/file.dump

should work. rvnewop is a package, and you should never cd into a 
package directory or include it into Python's search path in another 
way. The parent directory of the package directory should of course be 
in the search path, but you can trust pip to take care of that.



More information about the Tutor mailing list