1

I am making a python 3.6 program which involves the use of a few 3rd party modules. Is it possible to configure my program to use modules stored in the local folder (C:\Users\username\directory\filelocationfolder\modules) rather than the default location for modules installed to python (C:\Python36\Lib\site-packages)?

This way, I could send someone the folder containing my program and they would not need to have the required modules pre-installed.

I am somewhat new to Python, so I would appreciate if you could explain your answers.

rocketsnstuff
  • 103
  • 2
  • 2
  • 9
  • 2
    append the directory to `sys.path`. So, `sys.path.append("/path/to/folder")` And your `import` statements will check for corresponding files in that folder. – juanpa.arrivillaga May 15 '17 at 03:17
  • I tried this and it still doesn't work. What is the default directory? Would I have to specify the file location directly from the C drive, or could I just use ../FileLocation/Modules – rocketsnstuff May 15 '17 at 03:19
  • What "doesn't work". It should work. What exactly are you doing? What do you mean by "default directory"? Python `import` statements will check the working directory, and anything in `sys.path` – juanpa.arrivillaga May 15 '17 at 03:20
  • The program still doesn't recognise the modules. What I'm making is a script to encrypt and decrypt messages. – rocketsnstuff May 15 '17 at 03:24
  • 1
    Right, you need to show precisely what you are doing, or else we can't help you. "It doesn't work" is not a sufficient problem specification. – juanpa.arrivillaga May 15 '17 at 03:25
  • I have import sys and import pyperclip at the top of my document. I have put the pyperclip files in a directory together with the location of my program, as well as in C:\Python36\Lib\site-packages. When I remove it from site-packages but leave it in the other location, it says module not recognised – rocketsnstuff May 15 '17 at 03:29
  • Add the exact code above *in the question itself* not in the comments. – juanpa.arrivillaga May 15 '17 at 03:30
  • Possible duplicate of [How to import a module given the full path?](http://stackoverflow.com/questions/67631/how-to-import-a-module-given-the-full-path) – s-m-e May 15 '17 at 04:45

1 Answers1

0

use the sys lib for example you have directory C:\a and C:\b having scripts as a.py and b.py

then to import b.py into a.py do something like this

import os

import sys

sys.path.append(os.getcwd()+"/../b")

from b import *