I'm new to SublimeText2. So far I have found it excellent, but I just came across a problem I did not manage to solve. I'm trying to import a Python module, mechanize, into my script. However, whenever a run it (just the import mechanize line), I get:
Traceback (most recent call last):
File "/Users/gabrielbianconi/Desktop/test.py", line 1, in <module>
import mechanize
ImportError: No module named mechanize
[Finished in 0.3s with exit code 1]
However, when I run this line in Terminal, it works perfectly:
gb-air:~ gabrielbianconi$ python
Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import mechanize
>>>
I guess this is a problem with ST2. I saw that ST2 on Mac uses the system's python, so I don't see why it doesn't recognize the module.
Thank you very much.
Edit: I'm on OS X Mountain Lion.
I managed to solve this problem. ST2 was not using the same python as the Terminal. For anyone having the same mistake, you can solve this by selecting: Sublime Text 2 > Preferences > Browser Packages... Then go into 'Python' folder and open 'Python.sublime_build'. Now edit the 'cmd' parameter to match your desired Python path. For me (using MacPorts), the result was:
{
"cmd": ["/opt/local/bin/python", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With