Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
537 views
in Technique[技术] by (71.8m points)

sublimetext - Can't recognize Relative Paths when using Sublime text default Python when accesing .py files located on Windows network homegroup

I am trying to access and run .py files located on other machine (that is on the same Windows HomeGroup) using Sublime Text 3, on a Windows 10 machine. The files are located on the user AGUXSURFACEA, so I can easily access the files from sublime text, sublime text accepts the folder \AGUXSURFACEAProgramacion as a viable path.

However when I run code using Python's default as Build System, it is unable to recognize "relative paths". All the code can run, runs, but when it need to access a file on relative path, the interpreter show an error

For example:

import pandas as pd
import numpy as np
df = pd.read_csv('datasets/census.csv')

It imports all the libraries, but crashes in the end with this error:

'AGUXSURFACEAProgramacion' CMD.EXE se inici? con esta ruta como el directorio actual. No se permiten rutas UNC. Regresando de manera predeterminada al directorio Windows. ... FileNotFoundError: [Errno 2] No such file or directory: 'datasets/census.csv'

The complete error is:

'\AGUXSURFACEAProgramacionPseudotesis'
CMD.EXE se inici? con esta ruta como el directorio actual. No se permiten
rutas UNC. Regresando de manera predeterminada al directorio Windows.
Traceback (most recent call last):
  File "\AGUXSURFACEAProgramacionPseudotesisPruebas.py", line 5, in <module>
    df=np.genfromtxt("datasets/winequality-redcoma.csv", delimiter=",", names=True)
  File "C:python37libsite-packages
umpylib
pyio.py", line 1749, in genfromtxt
    fid = np.lib._datasource.open(fname, 'rt', encoding=encoding)
  File "C:python37libsite-packages
umpylib\_datasource.py", line 195, in open
    return ds.open(path, mode, encoding=encoding, newline=newline)
  File "C:python37libsite-packages
umpylib\_datasource.py", line 535, in open
    raise IOError("%s not found." % path)
OSError: datasets/winequality-redcoma.csv not found.
[Finished in 0.5s]

(Sorry the first part of the error is in spanish because of my windows language, it says something about UNC that has something to do with network path. The closest translation of the error on a native english version of windows i could find would be: "CMD.EXE was started with the above path as the current directory. UNC paths are not supported. Defaulting to Window directory.")

I have a workaround using PythonREPL, REPL works fine, but I don't like it that much because repl is a little uncomfortable, it won't mark all error with red color when running code, and also leaves old output until I click on restart.

Any help would be appreciated, thanks in advance.

Solution: I lack the knowledge to explain this solution however. Creating a new custom build for python, solves this issue once and for all. The "working dir" and "shell" lines are redundant in this code because (surprisingly) it works even without them. What i can say is that this WON'T work if the line "shell" has True as value. So creating a new .py with this code and saving it into C:Users"your user"AppDataRoamingSublime Text 3PackagesUser , and selecting the this as Build System in the build menu will make it work.

{
    //shell_cmd": "make"
    "cmd": ["python", "-u", "$file"],
    "file_regex": "^[ ]*File "(...*?)", line ([0-9]*)",
    "selector": "source.python",
    "working_dir": "$file_path",
    "shell": false
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...