Sublime Forum

Path setting of sublime for running python3.8(solved)

#1

When I ran import readany in sublime, I got the following report. But it could be executed in iterm2. I think that it is the problem about path variable. The path shown in below is the same with the result of the command /usr/libexec/path_helper -s. But I have add the work paths to $PATH in .bash_profile that seams to be ignored by sublime.
It work well until I upgrade to python3.8 from 3.7. (in macOS10.15)

Traceback (most recent call last):
File “/Users/william/Folders/script-1.py”, line 4, in
import readany
ModuleNotFoundError: No module named ‘readany’
[Finished in 0.1s with exit code 1]
[cmd: [‘python3’, ‘-u’, ‘/Users/william/Folders/script-1.py’]]
[dir: /Users/william/Folders]
[path: /Library/Frameworks/Python.framework/Versions/3.7/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin]

0 Likes

#2

Sublime Text uses your login shell to get environment variables. IIRC by default the login shell is zsh not bash, so you’ll want to use .zprofile instead.

1 Like

#3

Not solved thoroughly. I have changed the path of sublime by editing .zprofile.
The customized module readany is indeed in the path /Users/william/Programming/Python/mywork. However the error dose not disappear.

Traceback (most recent call last):
File “/Users/william/Folders/script-1.py”, line 4, in
import readany
ModuleNotFoundError: No module named ‘readany’
[Finished in 0.1s with exit code 1]
[cmd: [‘python3’, ‘-u’, ‘/Users/william/Folders/script-1.py’]]
[dir: /Users/william/Folders]
[path: /Users/william/Programming/Python/mywork:…

0 Likes

#4

Python doesn’t load modules from the PATH. If you want to add module locations for python you need to use PYTHON_PATH or have your module in the same path as the script (or any other default path for python modules).

0 Likes

#5

Thank you. It is PYTHONPATH, the path for python. but sublime could not load my modules from the given paths, while iterm2 could.

0 Likes

#6

Are you running the script from the same directory?

0 Likes

#7

No. It is possible to run scripts in different dirs. I always put my modules in a fixed dir, and import them anywhere before the error.

The module can be imported when the script runs in the same dir, the standard libs and the 3rd part can be imported too.

0 Likes

#8

So if you run the same script from /Users/william/Folders using python3 -u script-1.py it’s able to import the module readany from /Users/william/Programming/Python/mywork? Are you sure you haven’t set up a PYTHONPATH in your environment (echo $PYTHONPATH) that isn’t in .zprofile?

1 Like

#9

Yes, It could run in iterm2 by the command python3 -u or in the command line of python/ipython. I set the variable both in .zprofile and .bash_profile.

0 Likes

#10

It works well now. I just restarted sublime. Thank you very much

0 Likes