sublimeREPL - "can't open file '$file_basename'" - python-3.x

When I try to execute more than an operation using SublimeREPL and Python3 I get :
C:/Users/Name/Anaconda3/envs/keras/python.exe: can't open file '$file_basename': [Errno 2] No such file or directory.
Following this answer I have modified the sublime-settings file adding "default_extend_env": {"PATH": "{PATH};C:/Users/Simone/Anaconda3/envs/keras"}.
I have also add the path C:/Users/Name/Anaconda3/envs/keras/python.exe in Main.sublime-menu file, but I'm still getting the same error message.

You do not have to modify you sublime-setttings file. I suppose that you have your subl configured to run with python3 but it doesn't matter.
When you use ctrl + b for running your code, you must be sure that you have something written. Is only that, if you use ctrl + b but you don't have anything in your code file is normal that you were obtaining that error.

When your cursor not in the current python file [may be in output panel of the SublimeREPL or may be in empty tab/file] and if you are running
Tools->SublimeREPL->python->python - RUN currentfile
then you may get below error. Because there is no file's path for that output panel file or for an empty file.
C:/Users/Name/Anaconda3/envs/keras/python.exe: can't open file
'$file_basename': [Errno 2] No such file or directory
So, focus your cursor in the current python file and try it again.
This may be one of the case.I faced this problem and after few trials i figured it out.

did you save the file?
I have had the same problem. I saved the file and it worked

Related

Pycharm throws FileNotFoundError after refactor for some file [duplicate]

Recently, I'm unable to use relative paths in my code while using PyCharm. For instance, a simple open('test.txt', 'r') will not work - whereupon I am sure the file exists in the same level as the running py file. PyCharm will return this error.
FileNotFoundError: [Errno 2] No such file or directory:
After reading answers online on StackOverflow, I have tried multiple options including:
Changing test.txt to ./test.txt
Closing project, deleting the .idea folder, open the folder with code.
Reinstalling as well as installing the latest version of PyCharm.
Invalidating caches and restarting.
None of these options have worked for me. Is there someway I can tell PyCharm to refresh the current working directory (or even to see where it thinks the current working directory is)?
Edit: I should note that running the script in a terminal window will work. This appears to be a problem with PyCharm and not the script.
Change:
Run > Edit Configurations > Working directory,
which sets the working directory for a specific project. (This is on a Mac)
I have Pycharm 4.5, so things might have changed a bit.
Try going to Settings > Project > Project Structure
On this dialog, click your folder that has the source code in it, and then click the blue folder in the menu to note it as "source" folder. I believe this fixes a lot of the path issues in Pycharm
Here is the link to "content roots": https://www.jetbrains.com/pycharm/help/content-root.html
Current version 2019.2 somehow ignores "source root" from the "project structure". Here's how to actually enforce it:
Run -> Edit Configurations -> Python -> "Edit Templates" -> fill out "Working Directory"
__file__ refers to file path. So you can use the following to refer file in the same directory:
import os
dirpath = os.path.dirname(__file__)
filepath = os.path.join(dirpath, 'test.txt')
open(filepath, 'r')
In PyCharm, click on "run/edit configurations..."
Then find your script file in the "Python" dropdown menu. Check the "Working Directory" entry and change it if necessary.
EXACT ANSWER TO SOLVE THIS ISSUE ,,
GO TO EDIT CONFIGURATION (just LEFT side of GREEN CODE RUNNER ICON)
click on python (not any specific python script) ONLY SELECT PYTHON
then below right side click on [edit configuration templetes]
select current working dir by going into those blocks
It will change the CWD of all python file that exists in project folder..
then all file will understand the RELATIVE PATH that starts from your actual project name..
i hope this will resolve all your issue related path.
Sometimes it is different. I solved my problem by clicking "Run" at the Pycharm's toolbar and then "Edit Configurations..." and I change my Interpreter to another actual one. Just changing it in the settings does not help, but this opperation already does ;)
I too had the same issue few minutes ago...but,with the latest version of PyCharm it is resolved by simply using the relative path of that file..
For instance, a simple f = open('test', 'r') will work.
A little clarification for mac users. In mac, what #andere said above is correct for setting working directory. However, if your code is in a different folder, say working_dir/src/ (like classic java/scala file structure) in that case you still need to set your Sources Root. In mac's PyCharm this can be done by right clicking on the src/ folder > Mark Directory as > Sources Root. Helped me with lot of similar import issues. Hope this helps someone.

how can i check the location of my file in my computer which i have opened in python?

i am so much confused i am opening a file in python directly by using
f=open('RouteDB1.dat','r')
but the content of this file is not which it is supposed to be..i think it is getting this file from some other location..and i dont know that location..if i tried with different filenames then it is showing error file not found..i am using pycharm as IDE and it is showing CWD as scratches folder..although i changed my directory to the folder i want but still i am getting file not found error..it is so frustrating..plz help

I got a problem when I input any node cmd,

I got a problem when I input any npm cmd, it says
internal/modules/cjs/loader.js:584
Operating System: Windows 8 pro 64bit
What shall I do to solve this issue?
Your error message of:
Error: Cannot find module 'C:\Users\NUMAN ALI\myfirst.js'
indicates that Node can't find your myfirst.js file to run within your current directory of: C:\Users\NUMAN ALI. Your myfirst.js file isn't located within this directory so you need to move into the correct directory containing this file, or alternatively create this file in the current directory. Then you need to add your desired JavaScript within this file to run it.
With your comment of: "The file you have just created must be initiated by Node.js before any action can take place" I am going to assume you don't have this file in your current directory. Maybe you could try creating the file in a text editor, such as notepad at the very least on a Windows machine, and adding the JavaScript contents into this file. Then try re-running the file with a node myfirst.js. Check out this accepted answer here as I think this will help you out a lot. Also, for command line help for creating files, check out this link.
Hopefully that helps!

Cannot Find the Correct Working Directory in Python Spyder

I'm having trouble with the working directory in Spyder console. I'm trying to convert an xlsx file into a pandas array, but I keep getting the same error. I've changed the Run Directory in preferences and it should be the correct one.
screenshot of Spyder console
Sorry if this is a really newbie question I just really dont know where to go from here.
The path at the top right of the screen in Spyder will change the working directory of the IPython console. Set it to the desired working directory. Hit Ctrl+F6 to check the run configuration of your script and make sure it is set to run at the current work directory. See if that fixes the problem.
As others have mentioned, the os module provides a way of getting and changing the working directory directly through python, rather than changing the working directory settings in Spyder. Your second option is to do the following before importing the .xlsx file:
import os
os.chdir('C:/Users/mypath') # Change your working directory to your .xlsx file location
The other useful os function to check what your current directory is:
os.getcwd()
As for your current case, there isn't any issue. The runfile('', wdir='') text is simply letting you know which .py script you are running and for what working directory. There isn't any other output, because you haven't set anything to happen after you read the excel file to xls_file. Try adding a print(xls_file) statement to the end of your script and it should print the pandas DataFrame to the console.
(Spyder maintainer here) There's no error after you change your directory in the Run menu. runfile is the function used by Spyder to run a file in the IPython console. You are simply not getting any output after runfile because you're not printing anything. If you add the command print(xls_file) at the last line of your file, then you'll see the output.
You can always read a file giving the full path. From read_excel doc.
excelSheet = pd.read_excel(io="C://..//myfile.csv")

cygwin version of idle has erroneous I/O handling

I am using idle (python 2.5) via cygwin on a windows vista machine and when I try to open an already existing .py file I see the full file path
/home/aaron/C:/cygwin/home/aaron/script.py
on the banner of the freshly openned file window when I expect simply
/home/aaron/script.py
In addition, the file appears blank which makes sense...basically idle is opening up a nonexistent file in some fictitious path. So what is causing the problem and how to fix? Anyone?
I have the same problem, but I found a workaround is to use File->Path Browser menu. From there I can find the .py file and open it by double clicking the file name.

Resources