Python Forum
problem running program in VScode
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problem running program in VScode
#1
Now that I VScode to program with I have been making some stuff and getting used to the new program but I am having one problem. I have this line of code that opens a file with pickle. The line of code that I have will run if I double click the python file or run the code from the python IDEL but when I run it from VScode it says that it can't find my file. I assume that it is not looking in the right location but I don't know how to make it look in the right location. I tried to use os.path.join to give the directory of the file but I think I did it wrong because it did not work. The file is located in the same location as my program.

This is the code. Works if I run outside of VScode.
f = open('images.lib', 'rb')
This is what I have tried but did not work.
f = open(os.path.join('C:\Users\User\Desktop\Python\New folder\Number Game','images.lib'), "rb")
Reply
#2
don't use backslash on windows - either use forward slash or escape, e.g.
'C:\\Users\\User\\Desktop\\Python\\New folder\\Number Game'
your file is in the same folder with your script, but do you change the current working directory in VS Code integrated terminal?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Thank you, I have not done much with loading files form other locations on my computer. I guess I forgot how it worked. I have only recently started using VS Code how do I check to see if my current working directory in the VS Code integrated terminal is set properly?
Reply
#4
when you are on Terminal tab, you can see what is the current working directory. Normally it will be the same folder where the script is (i.e. if you haven't change it)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
Thank you.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in running a code akbarza 7 547 Feb-14-2024, 02:57 PM
Last Post: snippsat
  writing and running code in vscode without saving it akbarza 1 346 Jan-11-2024, 02:59 PM
Last Post: deanhystad
  Program running on RPi 3b+ Very Strange Behavior - Out of Bound Index MadMacks 26 3,055 Mar-07-2023, 09:50 PM
Last Post: MadMacks
  running a TensorFlow program Led_Zeppelin 0 880 Apr-07-2022, 06:33 PM
Last Post: Led_Zeppelin
  rtmidi problem after running the code x times philipbergwerf 1 2,398 Apr-04-2021, 07:07 PM
Last Post: philipbergwerf
  python to exe running problem Roshan 2 5,520 Mar-30-2021, 08:59 AM
Last Post: Roshan
  Python Program running a lot slower after change to Ubuntu hubenhau 1 2,843 Mar-02-2021, 05:01 PM
Last Post: Serafim
  Running A Parser In VSCode - And Write The Results Into A Csv-File apollo 5 4,541 Jan-14-2021, 08:58 PM
Last Post: snippsat
  Running Python 2.7 program ErnestTBass 2 2,716 Oct-21-2020, 08:06 AM
Last Post: snippsat
  read terminal text from running program AArdvark_UK 2 1,853 Aug-27-2020, 12:43 PM
Last Post: AArdvark_UK

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020