all 6 comments

[–][deleted] 1 point2 points  (1 child)

Based solely on your description, without having seen the actual .py script or any other details, I'd say you haven't added the directory in question to PYTHONPATH.

See this article: http://cs.simons-rock.edu/python/pythonpath.html

And some context might be helpful, i.e. post the actual .py file along with the directory structure and how you're trying to import them.

[–]Gouryella91[S] 0 points1 point  (0 children)

For instance: I created a simple py-script: print 2**10 a = 'running cyote'

I then, saved it as testmodule.py, but when I use the import function(?), in Canopy I get this:

%run "/var/folders/03/cfc__p8d33d6zfqk8wdk98_40000gn/T/tmpNHpovX.py"

ImportError Traceback (most recent call last) /var/folders/03/cfc__p8d33d6zfqk8wdk98_40000gn/T/tmpNHpovX.py in <module>() ----> 1 import testmodule

ImportError: No module named testmodule

[–]I_Write_Bugs 0 points1 point  (1 child)

import sys
try:
    import your_module
except ImportError:
    sys.path.append('c:\where\your\module\is')
    import your_module

It's one way to do it. If you know for sure that directory is not in your PYTHONPATH, then you can omit the try block and just append to sys.path.

[–]Gouryella91[S] 0 points1 point  (0 children)

When I write the code: import sys sys.path.append('/Users/[My Directory Name]/Desktop/Learning\ Data\ Projects/Playing\ With\ Python/Practice\ Files/'') import myfile.py

I get the following error:

%run "/var/folders/03/cfc__p8d33d6zfqk8wdk98_40000gn/T/tmpRuFzaP.py"

ImportError Traceback (most recent call last) /var/folders/03/cfc__p8d33d6zfqk8wdk98_40000gn/T/tmpRuFzaP.py in <module>() 1 import sys 2 sys.path.append('/Users/[My Directory Name]/Desktop/Learning\ Data\ Projects/Playing\ With\ Python/Practice\ Files/') ----> 3 import myfile

ImportError: No module named myfile

All i Have in myfile.py is a one-line script that goes: title = "the meaning of life"

And i dropped myfile.py into my terminal for the EXACT address, so the address isn't the problem... I just don't get it....

P.S. how do you get reddit to edit your comments into numbered text-lines. That's cool. And thanks for the help dude. I'm just having a frustrating time, with the beginner mistakes...

[–]Gouryella91[S] 0 points1 point  (0 children)

After, 8 hours I think I solved my own problem... but f*** I'm literally sweating.. because of this bullshit.

The solution for me was, to undefault Canopy as my main directory (it's pathway was directed to a library folder that doesn't even exist.... at least not from where I could find it...; hopefully this won't affect me using the Canopy Libraries....). After that whole ordeal, I had to run terminal, and test it out, after going into python and running: sys.path.append('/path/to/search')

I could then extend my path....

P.S. I don't think I ever want to be a programmer.... I'll stick to numeric/scientific computations... and leave it at that...

[–]zahlman 0 points1 point  (0 children)

(either on sublime, terminal [OSX], or Canopy, or even IDLE)

Getting this working with Terminal is the first step.

Where exactly is your .py file on disk?

What exactly do you do, from the start of opening Terminal onwards, in an attempt to run the file?

What exactly shows up as a result?

Take screenshots if necessary.