0

I am heavy user of the pandas library. In order to keep useful custom made helper functions related to pandas library, I decided to create a custom project (my_proj) and a module pandas.py in it. Now I am developing another custom module related to ssh protocol in the same project.

Modules are created with pycharm. Structure of the project is as follows:

my_proj/src/my_proj/pandas.py
my_proj/src/my_proj/ssh.py

Everythin is OK and works properly. When I want to use site package's pandas I execute import pandas as pd, when I want to use my_proj pandas, than I use from my_proj import pandas as mypd.

But, now in ssh.py I need site package's pandas (not my_proj pandas). If in ssh.py I use import pandas as pd, pycharm imports my_proj/src/my_proj/pandas.py instead of the pandas from site packages.

One solution would be to rename my_proj's pandas.py to something else, but I would like to avoid that if possible.

Is there another option to prevent loading library from current directory and import it from site packages?

What are my options?

user3225309
  • 1,183
  • 3
  • 15
  • 31

2 Answers2

2

At the end I will use the following procedure:

import sys
old_syspath = sys.path
sys.path = [path for path in sys.path if 'customspace' not in path]

import pandas as pd
sys.path = old_syspath

Basically, I am removing 'customspace' from sys.path, than importing pandas and puting sys.path back as it was.

I think this is minimal change and it is working.

user3225309
  • 1,183
  • 3
  • 15
  • 31
1

I think that you could tell python exactly what directory to pull pandas from. EX from my_proj/src/my_proj/ssh import pandas.

anonymous
  • 11
  • 1