I try to access ECM Drive path. and I was able to access the ECM Drive path in pycharm compiling system. but I wasn't able to access that in EXE file using pyinstaller.
I tested something and I can't access ECM system using EXE.
What's difference? How can I access ECM Drive using EXE file.
ADD Contents
I can find the path when I compile in pycharm. enter image description here
but I can't find the path in EXE. enter image description here
and I test run compiled EXE as administrator. but result is same. enter image description here
Code
import sys, os, shutil
from PySide6.QtWidgets import *
from multiprocessing import Process
import clipboard
import time
folder_path = [["U:/전사 폴더/NAS2/Control 3/01.기종별프로그램/2. 보유 프로그램/2. AET (승강기식)",
"U:/전사 폴더/NAS2/Control 3/01.기종별프로그램/2. 보유 프로그램/1. AMT (다층순환식)",
"U:/전사 폴더/NAS2/Control 3/01.기종별프로그램/2. 보유 프로그램/3. ACT (평면왕복식)"],
["U:/전사 폴더/NAS1/Public/[000 주차현장설계도면]/[DET] 승강기식/[DET_2015이후]",
"U:/전사 폴더/NAS1/Public/[000 주차현장설계도면]/[DMC] 다층순환식/[DMC_2015이후]",
"U:/전사 폴더/NAS1/Public/[000 주차현장설계도면]/[DMF] 평면왕복식/[2015이후]"],
["U:/전사 폴더/NAS2/Control 3/01.기종별프로그램/- 표준 프로그램/승강기식",
"U:/전사 폴더/NAS2/Control 3/01.기종별프로그램/- 표준 프로그램/다층순환식",
"U:/전사 폴더/NAS2/Control 3/01.기종별프로그램/- 표준 프로그램/평면왕복식"],
["U:/전사 폴더/NAS2/Control 3/02.기종별 표준 전기도면/2.승강기식(AET)/국내/표준",
"U:/전사 폴더/NAS2/Control 3/02.기종별 표준 전기도면/1.다층순환식(AMT)",
"U:/전사 폴더/NAS2/Control 3/02.기종별 표준 전기도면/3.평면왕복식(ACT)/DMF 전기도면(표준 BOM 전기도면)/평면왕복식 표준전기도면"]]
def copyFolder(path, file_path, fname):
shutil.copytree(os.path.join(path, file_path), os.path.join(fname, file_path))
print("복사 완료")
def copyFile(src, fname, dst):
shutil.copyfile(src, os.path.join(dst, fname))
print("복사 완료")
class MyWindow(QWidget):
def __init__(self):
super().__init__()
self.setupUI()
self.desktop_path = os.path.join(os.environ["HOMEPATH"], "Desktop")
os.chdir(self.desktop_path)
def setupUI(self):
self.setGeometry(800, 200, 300, 300)
self.setWindowTitle("PyStock v0.1")
self.lineEdit = QLineEdit(self)
self.combobox = QComboBox(self)
self.combobox.addItem("승강기식")
self.combobox.addItem("다층순환식")
self.combobox.addItem("평면왕복식")
self.folderCombobox = QComboBox(self)
self.folderCombobox.addItem("보유 프로그램")
self.folderCombobox.addItem("주차현장설계도면")
self.folderCombobox.addItem("표준 프로그램")
self.folderCombobox.addItem("표준 전기도면")
self.pb1 = QPushButton("폴더 다운로드")
self.pb2 = QPushButton("파일 다운로드")
self.pb3 = QPushButton("폴더 업로드")
self.pb4 = QPushButton("파일 업로드")
self.pb5 = QPushButton("경로 클립보드에 복사")
self.pb_test = QPushButton("TEST")
self.pb1.clicked.connect(self.folderDownloadButton)
self.pb2.clicked.connect(self.fileDownloadButton)
self.pb5.clicked.connect(self.copyClipboard)
self.pb_test.clicked.connect(self.test)
self.label = QLabel()
layout = QVBoxLayout()
saveLayout = QGroupBox("정보")
gridLayout = QGridLayout()
gridLayout.addWidget(self.lineEdit)
gridLayout.addWidget(self.combobox)
gridLayout.addWidget(self.folderCombobox)
gridLayout.addWidget(self.pb1)
gridLayout.addWidget(self.pb2)
gridLayout.addWidget(self.pb5)
gridLayout.addWidget(self.pb_test)
gridLayout.addWidget(self.label)
saveLayout.setLayout(gridLayout)
layout.addWidget(saveLayout)
self.setLayout(layout)
def test(self):
path = folder_path[self.folderCombobox.currentIndex()][self.combobox.currentIndex()]
print("path: ", path)
print("path Test: ", os.path.isdir(path))
# cnt = 0
# if (os.path.isdir(path)):
# filenames = os.listdir(path)
# for filename in filenames:
# if (self.lineEdit.text() in filename):
# file_path = filename
# cnt = cnt + 1
QFileDialog.getOpenFileNames(self, dir=path)
# if (os.path.isdir(path)):
# # 다운로드할 파일 위치 열기
# if cnt == 1:
# fnames, ftype = QFileDialog.getOpenFileNames(self, dir=os.path.join(path, file_path))
# else:
# fnames, ftype = QFileDialog.getOpenFileNames(self, dir=path)
def copyClipboard(self):
cnt = 0
# 기본 파일 경로 확인
path = folder_path[self.folderCombobox.currentIndex()][self.combobox.currentIndex()]
# 해당 경로에서 lineEdit에 기록된 프로젝트 번호를 포함하는 폴더명이 있는지 체크
if (os.path.isdir(path)):
filenames = os.listdir(path)
for filename in filenames:
if (self.lineEdit.text() in filename):
file_path = filename
cnt = cnt + 1
if (os.path.isdir(path)):
# 경로를 클립보드에 복사
if cnt == 1:
path = os.path.join(path, file_path)
clipboard.copy("내 PC/ECM Drive (U:)" + path[2:])
else:
clipboard.copy("내 PC/ECM Drive (U:)" + path[2:])
print(path[2:] + "가 클립보드에 복사되었습니다.")
def fileDownloadButton(self):
path = None
cnt = 0
file_path = None
# 기본 파일 경로 확인
path = folder_path[self.folderCombobox.currentIndex()][self.combobox.currentIndex()]
# try:
# print("(EXE)확인 결과: ", os.path.isdir(self.lineEdit.text()))
# os.chdir(sys._MEIPASS)
# print(sys._MEIPASS)
# except:
# print("(PYTHON)확인 결과: ", os.path.isdir(path))
# os.chdir(os.getcwd())
# print("찾을 위치: ", path)
# 해당 경로에서 lineEdit에 기록된 프로젝트 번호를 포함하는 폴더명이 있는지 체크
if (os.path.isdir(path)):
filenames = os.listdir(path)
for filename in filenames:
if (self.lineEdit.text() in filename):
file_path = filename
cnt = cnt + 1
if (os.path.isdir(path)):
# 다운로드할 파일 위치 열기
if cnt == 1:
fnames, ftype = QFileDialog.getOpenFileNames(self, dir=os.path.join(path, file_path))
else:
fnames, ftype = QFileDialog.getOpenFileNames(self, dir=path)
if fnames:
desktop_list = os.listdir(self.desktop_path)
cnt = 0
for desktop in desktop_list:
if (self.lineEdit.text() in desktop):
file_path = desktop
cnt = cnt + 1
if cnt == 1: # 파일 저장위치 결정
dst = QFileDialog.getExistingDirectory(self, dir=os.path.join(self.desktop_path, file_path))
else:
dst = QFileDialog.getExistingDirectory(self, dir=os.getcwd())
if dst:
print("파일 다운로드 시작")
os.chdir(dst)
for fname in fnames:
copyFile(fname, os.path.basename(fname), dst)
def folderDownloadButton(self):
path = None
cnt = 0
file_path = None
path = folder_path[self.folderCombobox.currentIndex()][self.combobox.currentIndex()]
if (os.path.isdir(path)):
filenames = os.listdir(path)
for filename in filenames:
if (self.lineEdit.text() in filename):
file_path = filename
cnt = cnt + 1
if (cnt == 1):
fname = QFileDialog.getExistingDirectory(self, dir=os.getcwd())
os.chdir(fname)
if not fname:
print("Cancel")
elif os.path.isdir(os.path.join(fname, file_path)):
print("동일한 이름의 폴더가 있습니다.")
self.label.setText("동일한 이름의 폴더가 있습니다.")
else:
print(file_path + "을(를) " + fname + " 로 복사합니다.")
self.label.setText(file_path + "을(를) " + fname + " 로 복사합니다.")
p = Process(target=copyFolder, args=(path, file_path, fname,))
p.start()
elif (cnt >= 2):
print("중복입니다.")
self.label.setText("중복입니다.")
else:
print("폴더를 찾을 수 없습니다.")
self.label.setText("폴더를 찾을 수 없습니다.")
if __name__ == "__main__":
#
# try:
# os.chdir(sys._MEIPASS)
# print(sys._MEIPASS)
# except:
# os.chdir(os.getcwd())
app = QApplication(sys.argv)
window = MyWindow()
window.show()
app.exec_()
ADD
I try to run in python 3.8. the result is same with EXE file. I think there is a difference between the pycharm project and python 3.8.
ADD
I confirmed when I compiled in anaconda virtual env, os.path.isdir("path") returns True, but when I compiled in python virtual Env or EXE file, os.path.isdir("path") returns False.