Unable to Use Numpy Properly

时间:2016-11-09 08:16:43

标签: python-3.x numpy

I have installed numpy using .whl file, specifically numpy-1.11.2-cp35-none-win_amd64

When I finish installing numpy, I run the script that I have posted below, and recieve this message..

Traceback (most recent call last): File "C:\Users\jack.UTILIS\Desktop\Components\SigmaTest(64).py", line 7, in <module> import numpy as np File "C:\Users\jack.UTILIS\AppData\Local\Programs\Python\Python35\lib\site-packages\numpy\__init__.py", line 142, in <module> from . import add_newdocs File "C:\Users\jack.UTILIS\AppData\Local\Programs\Python\Python35\lib\site-packages\numpy\add_newdocs.py", line 13, in <module> from numpy.lib import add_newdoc File "C:\Users\jack.UTILIS\AppData\Local\Programs\Python\Python35\lib\site-packages\numpy\lib\__init__.py", line 8, in <module> from .type_check import * File "C:\Users\jack.UTILIS\AppData\Local\Programs\Python\Python35\lib\site-packages\numpy\lib\type_check.py", line 11, in <module> import numpy.core.numeric as _nx File "C:\Users\jack.UTILIS\AppData\Local\Programs\Python\Python35\lib\site-packages\numpy\core\__init__.py", line 14, in <module> from . import multiarray SystemError: initialization of multiarray raised unreported exception

I have read that this message is due to the installation of the incorrect version on numpy. Am I missing something? This seems to be the correct version.

Here is my code.

#!/usr/bin/env python3.5.2

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


# make directory available with pathway to user

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 (x86)\\GDAL\gdal-data"
gdal_env["GDAL_DRIVER_PATH"] = "C:\\Program Files (x86)\\GDAL\\gdalplugins"
gdal_env["PATH"] = gdal_env["PATH"] + ";C:\\Program Files (x86)\\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 (x86)\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(64).py')
wheel_install_2 = os.path.expanduser(user + '\\Desktop\\Components\\Sigma_Test\\wheel_install_gdal(64).py')
ridofz = os.path.expanduser(user + '\\Desktop\\Components\\Sigma_Test\\ridofZsv2.py')
to_dB = os.path.expanduser(user + '\\Desktop\\Components\\Sigma_Test\\to_dBv2.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'] # hopefully this works


# 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")

except:
    print ("The packages are't installing properly")
    sys.exit()


# Create three new folders which will house the files that will be created
# along each sequential step of the script

newpath = os.path.expanduser(user + '\\Desktop\\Components\\Float32')
if not os.path.exists(newpath):
    os.makedirs(newpath)
newpath_2 = os.path.expanduser(user + '\\Desktop\\Components\\Zeros')
if not os.path.exists(newpath_2):
    os.makedirs(newpath_2)
newpath_3 = os.path.expanduser(user + '\\Desktop\\Components\\db_Files')
if not os.path.exists(newpath_3):
    os.makedirs(newpath_3)

# Run gdal_translate utilizing the original HV and VH polarization images
# then place them as float32 type within a Float32 folder on the users desktop

#hvfullCmd = ' '.join([gdalTranslate, cmd, src_dataset.fileName, dst_dataset])
subprocess.call([gdalTranslate] + cmd + [src_dataset.fileName, dst_dataset])
#vhfullCmd = ' '.join([gdalTranslate,cmd,srcVH.fileName,dstVH])
subprocess.call([gdalTranslate] + cmd + [srcVH.fileName, dstVH])

# Run gdal_calc.py for HV & VH Zeros opening seperate script that
# are housed within the folder that the user will download 

try:
    os.system(ridofz)
    print ("Zeros Removed")
    os.system(to_dB)
    print ("Converted to Decibels")

except:
    print ("This isn't working")
    sys.exit()

# Open both Rasters using GDAL

hvRaster = gdal.Open(db_HV)
vhRaster = gdal.Open(db_VH)

# Get RasterBand for both dB Polarization Files

hvRasterBand = hvRaster.GetRasterBand(1)
vhRasterBand = vhRaster.GetRasterBand(1)

# Get Raster Mean for both dB Polarization Files

hvMean = hvRasterBand.GetStatistics(0,1)[2]
vhMean = vhRasterBand.GetStatistics(0,1)[2]

# calculate stDev

rasterList = (hvMean,vhMean)
stDev = np.std(rasterList)

print (stDev)

# Print a statement that will notify the user whether or not the sigma value is acceptable 

if stDev >= 0.06:
    print ("The imagery isn't acceptable, the σ value is" ,stDev)


if stDev <= 0.06:
    print ("The imagery is acceptable, the σ value is", stDev)

# Create a text file that reports the files that were used
# and when those files were utilized

def timeStamped (fname, fmt='{fname}_%Y-%m-%d-%H-%M-%S .txt'):
    return datetime.datetime.now().strftime(fmt).format(fname=fname)
with open(timeStamped('files_used'),'w') as outf:
    outf.write("###" + sttime + "####")
    outf.write(" \n")
    outf.write("#######################################")
    outf.write(" \n")
    outf.write("SIGMA TEST -- UTILIS ISRAEL LTD.")
    outf.write(" \n")
    outf.write("#######################################")
    outf.write(" \n")
    outf.write(" \n")
    outf.write(src_dataset.fileName + sttime)
    outf.write(" \n")
    outf.write(srcVH.fileName + sttime)
    outf.write(" \n")
    #outf.write(int(stDev) + sttime)
    outf.write(" \n")
    outf.close()

# Remove unecessary folders from PC

shutil.rmtree(newpath)
shutil.rmtree(newpath_2)

0 个答案:

没有答案