0

A Python script runs fine if I start it manually in a command prompt (CMD), e. g.

Script P:\theproject\thescript.py:

import pymssql
if __name__ == "__main__":
    files = open('test.txt','a')
    files.write('this is a test')

Run manually:

C:\Users\theuser\AppData\Local\Programs\Python\Python39\python.exe P:\theproject\thescript.py

However, when double-click onto the file thescript.py, the command prompt opens and closes immediately without any action having taken place, i. e. the file test.txt is not written. This problem is similar to the general case. However, it seems to be due to the library pymssql specifically. If I comment the first line (see below) and start with double-click, it runs fine, i. e. the file test.txt is written.

#import pymssql
if __name__ == "__main__":
    files = open('test.txt','a')
    files.write('this is a test')

Why is there a problem with pymssql being imported, and how can I make the script callable with double-click and pymssql being imported?

I'm working with Windows 10 Pro and Python version 3.9.5.

stonebe
  • 482
  • 1
  • 3
  • 14
  • I bet it is an access issue since `test.txt` specifies a relative path. Try `import os`, then `print(os.path.abspath(os.curdir))` and `raw_input()` to find out what the current directory is, even when you double-click the Python script… – aschipfl Aug 18 '21 at 11:23
  • This might be true. However, the same issue occurs with no file creation, e.g. with line 3 ``yourentry = input("Your entry: ")`` and line 4 ``print(yourentry)``. – stonebe Aug 18 '21 at 11:32

0 Answers0