Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm just starting with Python and I need to import xclip in Python to make a program run.

The problem appears when I run the program. I get

Traceback (most recent call last):
  File "/home/jorgekadri/CesarCyhper.py", line 4, in <module>
    import xclip
ImportError: No module named xclip

I've already installed xclip by:

sudo get-apt install xclip

But when I want to import it in Python, it won't run.

This is my code

Caesar Cipher http://inventwithpython.com/hacking

import pyperclip

#the string to be encrypted/decypted
message = 'this is my secret message.'

#the encryption/decryption key
key = 13

#tells the program to encrypt or decrypt
mode ='encrypt'

#every possible symbol that can be encrypted
LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

# stores the encrypted/decryted form of the message
translated=''

#capitalize the string in message
message = message.upper()

#run the encryption/decyptio code on each symbol in the message string
for symbol in message:
    if symbol in LETTERS:
        #get the encrypted(or decrypted) number for this symbol
        num = LETTERS.find(symbol)#get the number of the symbol
        if mode=='encrypt':
            num=num+key
        elif mode == 'decrypt':
            num=num-key

            #hanble the wrap-raound if num is larger than the length of
            #LETTERS or less than 0
            if num >= len(LETTERS):
                num = num-len(LETTERS)
            elif num < 0:
                num = num + len(LETTERS)

            #add encrypted/decrypted numbers symbol at the ned of the translated
            translated=translated+LETTERS[num]

        else:
            #just add the symbol without encrypting/decrypting
            traslated = translated + symbol

#print the encrypted/decrypted string to the screen
print(translated)

#copy the encrypted/Decrypted string to the clipboard

pyperclip.copy(translated)

In the website http://invpy.com/pyperclip.py says that I can get Pyperclip from there.

Also in the website says: " On Linux, this module makes use of the xclip command, which should come with the os. Otherwise run "sudo apt-get install xclip"

I have the xclip working in my Terminal, the problem is that in Python I need to import xclip but when I do it I get the Error what I show in the begging.

share|improve this question
1  
There's no such thing as Python bindings for xclip, as far as I can see. The xclip package is littery a "command line interface to X selections". This does not provide any Python bindings. What program are you trying to run? –  gertvdijk Apr 18 '13 at 8:41
    
I'm just trying to run a Ceasar Cypher Program –  Jorge Apr 18 '13 at 8:48
    
Source Code of the Caesar Cipher Program Type in the following code into the file editor, and then save it as caesarCipher.py. Press F5 to run the program. Note that first you will need to download the pyperclip.py module and place this file in the same directory (that is, folder) as the caesarCipher.py file. You can download this file from invpy.com/pyperclip.py When I go to that Address, Im able to download it but in the code the first line says import xclip –  Jorge Apr 18 '13 at 8:51
    
Please include additional information in your question by editing it, rather than posting this in comments. This is a Q&A site, not a discussion forum, you see? –  gertvdijk Apr 18 '13 at 9:30
    
The code you linked does not do any import xclip! It runs the shell command xclip. I don't know why you get the line 4, in <module> import xclip error, as on line 4 there's no such code. Please link to the actual code you used. And again, please do so by editing your question. –  gertvdijk Apr 18 '13 at 9:32
show 5 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.