0

I am using a python package called kRPC that requires a basic boilerplate of setup code to use in any given instance, so here's my question:

Once I create a generic 'kRPCboilerplate.py', where can I place it inside my Python27 directory so that I can simply type,

import kRPCboilerplate

at the beginning of all my files?


I want to install my custom Python file to my Python directory so that I don't have to copy and paste the file into every new project folder I make.

I understand that,

import boilerplate

will import 'boilerplate.py', but only if 'boilerplate.py' is set in the root directory relative to the Python file that imports it.

The program I am creating will not be distributed, so there is no need to make a module installer, which is above the scope of my abilities. I simply want to copy and paste 'kRPCboilerplate.py' to the proper directory so that I can use Import without ever having to specify a path or copy and paste the imported file into the relative directory.

2 Answers 2

1

Your module root directory is 'Python27\Lib' where Python27 is your main python folder which includes the python executable file. You can drag and drop the .py files into there and import it without any complications!

Sign up to request clarification or add additional context in comments.

Comments

0

Bit late to reply, but the safest is to set a special environmental variable called PYTHONPATH which will add search location for Python to search for libraries:

eg in Linux terminal: export PYTHONPATH=$PYTHONPATH:/path/to/file

note it is only the path to the file, not the filename.

If you want a more permanent solution you can add export PYTHONPATH=$PYTHONPATH:/path/to/file to your ~/.bashrc or ~/.profile file

In windows the environmental variables are set in the config panel.

Not sure about OSx

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.