1

I have the following folder structure:

A/fold1/MyLib/package/

in which I have an __init__.py file and a file with the functions I need, let's call it file.py.

When I work from this path:

A/fold1/myProject/script.py

I try to import it but it looks like this library can't be found.

I have already worked, and it was fine when I had a structure like this:

A/fold1/myProject/package/file.py

where package contained also the __init__.py file.

I also got suggestions from the Spyder IDE. What I used, to make it work was to import like this:

if packagePath not in sys.path:

    sys.path.append(packagePath)

import package.file as f

But currently it doesn't work, and I don't even get the suggestions from the Spyder IDE.

Is there a way to import from the specified structure?

I wanted a folder with all my functions, and if possible to have it in this folder and not between the hundreds of libraries of python.

Thanks!

ParthS007
  • 2,581
  • 1
  • 22
  • 37
drSnake
  • 11
  • 4
  • Are you using the full-path in ``packagePath``? From your description it seems that you have moved the module into a "MyLib" folder outside "myProject". – Prasanth Oct 13 '19 at 06:42
  • don't use spyder for developement, use pycharm, to solve your problem, you need to make a base folder and acccording to base folder you need to import in files. lets say A is base folder, then to import file.py in script.py you need to use `from A.fold1.MyLib.package.file import function` use it like this – sahasrara62 Oct 13 '19 at 07:14
  • thanks prashant! @prasanth yes I've moved it outside to make it like general for any other project. – drSnake Oct 14 '19 at 07:07
  • Just a hunch: can you delete all ``*.pyc`` files in ``myProject`` and other directories. In the past I have tried this, successfully, to get python to refresh a module. – Prasanth Oct 14 '19 at 09:35

0 Answers0