path = os.path.realpath(__file__)
try:
shutil.move(path, "C:\\Users\\pc\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup")
except:
pass
try:
if os.path.exists("C:\\Users\\pc\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\{}".format(os.path.basename(__file__))):
os.remove(path)
except:
pass
使用pyinstaller后,我在python中的整个代码块不再起作用,因此不会将文件移至目标位置。请记住,它仅通过运行python脚本即可工作,因此我如何使其适应于使用pyinstaller使其成为.exe文件(有效的文件)
答案 0 :(得分:0)
from django.conf import settings
from django.test import TestCase
class MyTestCase(TestCase):
default_password = settings.TEST_USER_PASSWORD
# ... the rest of my stuff
仍指向脚本名称,该名称已解压缩到一个临时目录中。
PyInstaller和Py2exe都将sys.executable覆盖到应用程序的路径,例如:__file__
。
您可能需要浏览docs以获得详细信息。