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
}