0

I can't find an exact answer for this..

I have a compiled .pyc file. I have a reference to it in another python file. Where does the pyc file need to be for Python to find it? Whenever I run this I get an error saying there is no module found when it tries to import it.

It works fine if the uncompiled reference file (.py) is in the directory with the .py file I'm trying to run.

Do I need to update some path variables or put this in a special folder so it will find it? I realize that this isn't necessary; I mostly want to figure out how Python is pulling its imports in. Everything I've read has suggested that the .pyc file I have SHOULD run just fine when another needs to import it, even if there is no source .py around.

Edit: Clarification, I'm running Windows.

Akron
  • 1,413
  • 2
  • 13
  • 28
  • Has the .pyc file been compiled with the same version of Python that you are trying to run it under? – Ned Deily Apr 18 '15 at 06:26
  • Directories in `sys.path` are searched, you can modify that in your program, and/or use the `PYTHONPATH` environment variable. Make sure that the `.pyc` file has been created using the same Python version as the one you are using. Don't mix 64 and 32-bit python and pyc files. – cdarke Apr 18 '15 at 06:40
  • If your script is ssr.py, and then it's compiled version is ssr.pyc - then the same searching rules for ssr.py will work for ssr.pyc. So, if you have `import ssr` and there's no ssr.py newer than the existing ssr.pyc in the same directory - the ssr.pyc will be imported. – boardrider Apr 19 '15 at 11:38

0 Answers0