1

I have downloaded the pycrypto module for python 3, so I Can use AES in my python code. (EG if I have a code called encodeUsingAES.py)

However, this wouldn't work if I just copied encodeUsingAES.py to a different computer and ran it right? Because it doesn't have the pycrypto module installed so it will pop up heaps of errors.

I tried just copying the Crypto folders inside pycrypto into the same directory as my .py file but it didn't work.

Is there anyway for my to have all the files I need in the same directory so when I compress and send the folder the recipient can just run the .py file without having to install extra modules?

Thanks!

from Crypto import Random
from Crypto.Cipher import AES

EDIT: Tried this didn't work

import sys
sys.path.append("/pycrypto")
from Crypto import Random
from Crypto.Cipher import AES

$ python3 testCrypto.py
  Traceback (most recent call last):
    File "testCrypto.py", line 5, in <module>
    from Crypto import Random
  ImportError: No module named 'Crypto'

or

import sys
sys.path.append("pycrypto/lib")
from Crypto import Random
from Crypto.Cipher import AES

$ python3 testCrypto.py
  Traceback (most recent call last):
    File "testCrypto.py", line 5, in <module>
      from Crypto import Random
     File "pycrypto/lib/Crypto/Random/__init__.py", line 28, in <module>
      from Crypto.Random import OSRNG
    File "pycrypto/lib/Crypto/Random/OSRNG/__init__.py", line 32, in <module>
      from Crypto.Random.OSRNG.posix import new
    File "pycrypto/lib/Crypto/Random/OSRNG/posix.py", line 66
      except IOError, e:
Friedpanseller
  • 654
  • 3
  • 16
  • 31
  • If you use the path `/pycrypto`, it means that pycrypto is a folder in the root of your system. If you remove the `/` the directory should be relative to your working directory. – PinkFluffyUnicorn Apr 03 '17 at 11:52
  • @PinkFluffyUnicorn same thing, File "testCrypto.py", line 5, in from Crypto import Random ImportError: No module named 'Crypto' – Friedpanseller Apr 04 '17 at 05:35
  • http://stackoverflow.com/questions/9059699/python-use-a-library-locally-instead-of-installing-it should help you – PinkFluffyUnicorn Apr 04 '17 at 06:24

1 Answers1

0

If you copy the complete folder, you should add it to your path to be able to import it.

import sys
sys.path.append("/path/to/your/crypto/directory")

from Crypto import Random

If the pycrypto folder is directly placed in your project folder, following statement should work.

sys.path.append('./pycrypto')

PinkFluffyUnicorn
  • 1,260
  • 11
  • 20
  • but lots of files inside Crypto.Random has "from Crypto import Someotherthing", they don't have sys.path.append so they can't find the correct files? – Friedpanseller Apr 03 '17 at 09:33
  • I think sys.path is linked to your Python session, so once you modify your path, it should be visible in all python files. Or do you experience issues with this ? – PinkFluffyUnicorn Apr 03 '17 at 09:34