Problem importing files into python3

Hi everyone!

A few days ago I tried to import ROOT inside my python shell, but it wouldn’t work so I was advised to use python 3 every time and in fact, it works well and it lets me import ROOT.

However, I found out that I cannot import any file anymore, even though I give the path to python via the sys.path.insert() command.

Any idea why that is?

Any suggestion for solving this problem?

What changed between the time it worked and the time it stopped working?

Thank you for your interest1

I was using python2 before, but with python 2 I couldn t import ROOT.

Now I am using python 3 which lets me import ROOT but not files from a specific directory.

Hummm … is that directory on the Python Path? is there remnant of their use in python 2?

I added that directory using sys.path.insert()

I don t really know about any remnant of their use in python2, see here is the thing: It is actually a folder inside my home directory so I guess I can access it using python 2 because it is just my home directory.

Hi @zimmik44,

Can you check that the Python modules you want to use are in the PYTHONPATH?

To add directories with modules to your PYTHONPATH, you can do:
export PYTHONPATH=directory_with_modules:$PYTHONPATH

If a module is in the PYTHONPATH, for sure Python will find it when you import it.

Another thing to take into account is: did you install the modules that you want to use also for Python3? It might be the case that you installed them with Python2, now you moved to Python3 but the modules are not installed.


In the end I managed to definitely solve the problem myself, thank you anyways!

To help other reading this post and having similar problem, how did you solve the problem?

Yes, sure. The problem, in the end, was that I was not giving the full path, but only a part of it.
Once I gave the full path, it was working perfectly

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.