当前位置: 动力学知识库 > 问答 > 编程问答 >

operating system - OS Pathway Cannot be Found While Using Subprocess

问题描述:

Hello I am having an issue finding the pathway to a folder on a remote pc using os.path.expanduser and subprocess.call. In the code that I have posted below the user name C:\Users\Joe Schmo\ cannot be found, instead the script breaks at C:\Users\Joe I have used the method of placing the path '~/' However, it doesn't seem to be working. I would appreciate any help that could be provided.

#!/usr/bin/env python3

import os

import sys

import gdal

from gdalconst import *

import numpy as np

import math

import subprocess

from subprocess import call

import math

from tkinter import *

import datetime

from tkinter import filedialog

import shutil

#set user so that this script may run remotely

user = os.path.expanduser('~/')

# make dictionary of environmental variables

gdal_env = os.environ.copy()

# modify and add variables

gdal_env["GDAL_DATA"] = "C:\\Program Files\\GDAL\gdal-data"

gdal_env["GDAL_DRIVER_PATH"] = "C:\\Program Files\\GDAL\\gdalplugins"

gdal_env["PATH"] = gdal_env["PATH"] + ";C:\\Program Files\\GDAL"

# Set all of the necessary constants so that the script can create and save the pertinent files

# on the users desktop

src_dataset = Tk()

srcVH = Tk()

gdalTranslate = 'C:\\Program Files\\GDAL\gdal_translate.exe'

src_dataset.fileName = filedialog.askopenfilename(title="Select HV File")

srcVH.fileName = filedialog.askopenfilename(title="Select VH File")

dst_dataset = os.path.expanduser(user + '\\Desktop\\Components\\Float32\\newHV32.img')

dstVH = os.path.expanduser(user + '\\Desktop\\Components\\Float32\\newVH32.img')

sttime = datetime.datetime.now().strftime('(Time_Run = %Y-%d-%m_%H:%M:%S)')

wheel_install_1 = os.path.expanduser(user + '\\Desktop\\Components\\Sigma_Test\\wheel_install_numpy.py')

wheel_install_2 = os.path.expanduser(user + '\\Desktop\\Components\\Sigma_Test\\wheel_install_gdal.py')

ridofz = os.path.expanduser(user + '\\Desktop\\Components\\Sigma_Test\\ridofZsv2.py')

to_dB = os.path.expanduser(user + '\\Desktop\\Components\\Sigma_Test\\to_dBv3.py')

db_HV = os.path.expanduser(user + '\\Desktop\\Components\\dB_Files\\newHVdB.img')

db_VH = os.path.expanduser(user + '\\Desktop\\Components\\dB_Files\\newVHdB.img')

cmd = ['-ot', 'float32','-of', 'HFA']

# Install necessary packages, which are GDAL and Numpy

try:

os.system(wheel_install_1)

print ("GDAL intalled")

os.system(wheel_install_2)

print ("Numpy installed")

分享给朋友:
您可能感兴趣的文章:
随机阅读: