Sign in to follow this  
koka282

How to import a custom module?

Recommended Posts

hi,

 i have a custom module, I want to put it in the directory to import it. What should I do?

 

i got this error :

importError: No module named 'pyperclip' 

 

 

?i use Linux Debian

 

i downloaded the module from :

 

https://pypi.python.org/pypi/pyperclip/

 

 

what should i do to import it  sad.png

 

i tried many commands in Konsole sad.png

 

like sudo apt-get install python3-setuptools etc....

 

 

sad.png 

 

 

 

Thanks

Edited by koka282

Share this post


Link to post
Share on other sites

You are running Python - IDLE(Shell) from a location outside from where your script is located.

 

Option 1). Open the directory where the pyperclip.py file is located. Then right click on it and select edit with Python - IDLE. This will change IDLEs current working directory.

Option 2). Open up Terminal and CD to the location of pyperclip.py then run the command: python pyperclip.py.

 

Now you'll be able to import pyperclip.py with:

import pyperclip

Share this post


Link to post
Share on other sites

Install pip and pip install pyperclip

 

OR

 

cd pyperclip

python setup.py install

 

Make sure you're running terminal as su

 

Why pip? Pip is a light tool that makes it really easy to install future packages you just go pip install name-of-the-package so give it a try, most people use it. There's other tools like it I believe if you want to search for it.

 

For other packages it's similar.

 

Importing should work after that

Edited by olaolaola

Share this post


Link to post
Share on other sites

Python does not know where to find the module you're trying to load.  It normally only looks in the configured system installation path, and that depends on a number of factors (given you're running KDE my guess is you're on Linux, so I'll point out it depends on the Python version and the distro you're running).

 

To add additional search paths for importing modules when running Python, use the PYTHONPATH environment variable.  In your Konsole shell, try

 

  PYTHONPATH=~/pythonpractice python

 

This is assuming you have a file called ~/pythonpractice/pyperclip/__init__.py (which is the file Python will be looking for when you import pyperclip).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this