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
447 views
in Technique[技术] by (71.8m points)

python - Issue with os.listdir when a script is executable with pyinstaller

I have created a script that takes a file from one folder and produces another file in another folder. This is a project to convert one format into another to be used by people who do not have strong background in informatics so I have created a folder with the script plus the input folder and the output folder. The user just need to put the input file in the input folder and take the results from the output folder.

The script works fine if I run this python script when running with visual code as well as If I run the script using the terminal ( python CSVtoVCFv3.py )

but when I convert my script in an executable with pyinstaller I found the next error.

 File "CSVtoVCFv3.py", line 99, in <module>
FileNotFoundError: [Errno 2] No such file or directory: '/Users/manoldominguez/input/'
[99327] Failed to execute script CSVtoVCFv3

The code used in line 99 is:

97 actual_path = os.getcwd()
98 folder_input = '/input/'
99 input_file_name = os.listdir(actual_path+folder_input)
100 input_file_name= ''.join(input_file_name)
101 CSV_input = actual_path+folder_input+input_file_name

I have also tried this:

actual_path = (os.path.dirname(os.path.realpath('CSVtoVCFv3.py')))

So as conclusion as far as I can understand the issue is:

In these lines If I run my script I get this

os.getcwd()
# and
(os.path.dirname(os.path.realpath('CSVtoVCFv3.py')))
# give me this

'/Users/manoldominguez/Desktop/CSVtoVCF/input/'

If my script is ran with my executable I get this

'/Users/manoldominguez/input/'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
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

1.4m articles

1.4m replys

5 comments

56.7k users

...