When I set up a profile for python 3.4 in script , I can no longer use relative path for opening text files


#1

I recently downloaded python 3.7. One of my projects that I am currently working imports a module only compatible for python 3.4.3, which I have. I created a profile for atom using the directory of python 3.4 on my computer, with the command python3.4. It works, but I can no longer use relative path in my projects or else the compiler doesn’t recognize the file as existing an example of this would be:

with open(“adminRoles.txt”, “r”) as text_file:
#code here

has turned into:

with open("/fullpathtofile/adminRoles.txt", “r”) as text_file:
#code here

any ideas


#2

You did not do this, because Atom has no profile system and has no idea of how to run Python code. What I think you mean is that you created a profile for the package script (you haven’t specified, but I know enough to make an educated guess).

There have been other threads posted here with similar issues of not being able to use a relative path in Python under script. My supposition is that the script package makes the call in such a way that the project folder is not provided as the current working directory, even though that’s the default behavior for BufferedProcess. If 3.7 works and 3.4 doesn’t, that’s strange.

If you’re doing complex things with Python, you might find it useful to run your code with a package that gives you more control over the commands being issued, like process-palette.


#3

Sorry for not clarifying, I was in a hurry. Yes, I created a profile for script. I am making a discord bot and discord.py is not compatible with python 3.7. I have python 3.4 installed, but script defaults to a 3.7 compiler. I made a profile for 3.4 in script. I specified the directory of the version and the command(python3.4). It works, but now in my code I cannot use a relative path for things like:

with open(“adminRoles.txt”, “r”) as text_file:
#code here


#4

I used to be able to use relative path, as I have had python 3.4 for a long time. Now I cannot, after installing 3.7 and making the 3.4 profile in script


#5

Please post a screenshot of the profile as you have it configured.


#6


#7

And this works fine as a compiler, but no relative path when in atom:(
It runs fine on terminal with relative path, but that process is longer than just running it straight from atom, so this would really help. Thank you for your time


#8

Have you tried any other packages, such as process-palette or termination, in order to determine that it is Atom at fault, or are you just assuming based on your experience with script? If process-palette works (I would be tremendously surprised if it didn’t), then that will be just as fast as (or faster) than script. However, in this case I think it’s just the profile you’ve set up. What’s the full path you’ve set for the current working directory? It doesn’t look to me like the sort of folder that adminRoles.txt would live in. It looks to me like you’re pointing the CWD at a Python folder when the CWD you want is your project folder.


#9

Hello.

My opinion is that the working directory is not where you want it. The Python script is called as absolute path; the path is not changed.

It should be possible to get to this point by the arguments or something like that. There is useful info in the script project - https://atom.io/packages/script .A good read.

One such is the tip to call Atom in the command line with the path of the project. In my case in Windows I would open command prompt and type the command as atom d:/zoo/powershell. This activates my Powershell project directory in the forefront.

Start Atom with this path call and see it is works for you.

Cheers.


#10

This is identical to opening an empty Atom and using Add Project Folder or Open to add the folder you want.

To see what the CWD is from within Python, you can always run this script:

import os
print os.getcwd()

For an unconfigured script, it should always be your first project folder.