Python Forum
Including modules in Python using sys.path.append - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Including modules in Python using sys.path.append (/thread-29224.html)



Including modules in Python using sys.path.append - JoeDainton123 - Aug-23-2020

Hi all

I was hoping for some advice.

My company has python version 3.5 IDLE.

My company is NOT a software company, i have started using it to automate some of my tasks.

The issue is that modules such as pandas or numpy is not installed and these modules will never be installed (no specific reason was given).

However i have discovered that .py files that are not installed or party of the standard library can be included using the following code:-
import sys
sys.path.append("C:\Users\Joe\Test")
Test is a folder that contains various .py files.

I have pandas installed on my personal computer so I wanted to copy the pandas.py file from my personal computer into my work computer and put it in the Test folder shown above but i cannot seem to find pandas.py or numpy.py

My work computer is heavily restricted, i cannot access the c drive hence why i am trying to find an alternative method.

Any ideas?

Thank you.

I saw youtube video https://www.youtube.com/watch?v=CqvZ3vGoGs0&t=638s


RE: Including modules in Python using sys.path.append - millpond - Aug-24-2020

There are no .py files for these type of libraries because they are collections of smaller utilities. In short numpy and pandas are directories. Their functions (.py files) are imported after they are called.

Typically they live under '/site packages' either under C:\Pythonxx\lib or C:\Users\(user)\AppData\Roaming\Python\Python3x\site-packages.

Importing the path must be done within your script, and will only live as long. To make any changes permanent you *must* have C: drive access. In lieu of that, you can install to any dir using:
pip install --install-option="--prefix=$PREFIX_PATH" package_name

HOWEVER: Both packages must be compiled from source, and compiler access may be limited on a worker machine.

The solution I use here on Windows is:
https://www.lfd.uci.edu/~gohlke/pythonlibs/

Where precompiled wheels are offered for Win.

Also, I beleive the correct format for the import dir is:
C:\\Users\\Joe

That said, if as a n00b I am overlooking some obvious subtlety, hopefully someone will correct this bit of advice. I've just installed Python38 on two Win machines with around 5000 packages each, so this kind of stuff is fresh in my head!