我现在正在使用mac并尝试使用模块pypng。我从pip install pypng安装了模块。它运作良好。但是,当我运行我的应用程序python test.py(其中test.py内部有' import png')时,它给出了一个错误,指出' ImportError:没有名为png'的模块。
然而,当我从命令行进入python环境时,我键入' import png',它没有错误,为什么会这样。我甚至重新启动计算机,但仍然遇到麻烦。
当我安装pypng模块时,它告诉我它安装在/Users/abc1/anaconda/lib/python2.7/site-packages中,在这个目录里我可以找到png.py和png.pyc。 / p>
当我打印sys.path时,这是输出,看起来它没有从/Users/abc1/anaconda/lib/python2.7/site-packages加载png包。我该如何解决呢?
['/Applications/Blender/blender.app/Contents/Resources/2.76/scripts/addons_contrib', '/Applications/Blender/blender.app/Contents/Resources/2.76/scripts/addons', '/Applications/Blender/blender.app/Contents/Resources/2.76/scripts/modules', '/Applications/Blender/blender.app/Contents/Resources/2.76/scripts/startup', '/Applications/Blender/blender.app/Contents/MacOS/../Resources/2.76/scripts/modules', '/Applications/Blender/blender.app/Contents/Resources/2.76/python/lib/python34.zip', '/Applications/Blender/blender.app/Contents/Resources/2.76/python/lib/python3.4', '/Applications/Blender/blender.app/Contents/Resources/2.76/python/lib/python3.4/plat-darwin', '/Applications/Blender/blender.app/Contents/Resources/2.76/python/lib/python3.4/lib-dynload', '/Applications/Blender/blender.app/Contents/Resources/2.76/python/lib/python3.4/site-packages', '/Applications/Blender/blender.app/Contents/MacOS/../Resources/2.76/scripts/freestyle/modules', '/Applications/Blender/blender.app/Contents/Resources/2.76/scripts/addons/modules', '/Users/xisizhe/Library/Application Support/Blender/2.76/scripts/addons/modules']
答案 0 :(得分:1)
也许您在命令行中将png
安装到python环境中,而不是在运行脚本的环境中安装python batch.py
。尝试在命令行中使用/Users/abc1/anaconda/lib/python2.7/site-packages
,或将sys.path
追加到google.charts.load('41', {packages: ['bar']});
google.charts.setOnLoadCallback(startChart);
function startChart() {
var data = new google.visualization.arrayToDataTable([
['Galaxy', 'Distance', 'Brightness'],
['Canis Major Dwarf', 8000, 23.3],
['Sagittarius Dwarf', 24000, 4.5],
['Ursa Major II Dwarf', 30000, 14.3],
['Lg. Magellanic Cloud', 50000, 0.9],
['Bootes I', 60000, 13.1]
]);
var options = {
width: 900,
chart: {
title: 'Nearby galaxies',
subtitle: 'distance on the left, brightness on the right'
},
series: {
0: {
axis: 'distance'
}, // Bind series 0 to an axis named 'distance'.
1: {
axis: 'brightness'
} // Bind series 1 to an axis named 'brightness'.
},
axes: {
y: {
distance: {
label: 'parsecs'
}, // Left y-axis.
brightness: {
side: 'right',
label: 'apparent magnitude'
} // Right y-axis.
}
}
};
var chart = new google.charts.Bar(document.getElementById('dual_y_div'));
chart.draw(data, options);
var chart1 = new google.charts.Bar(document.getElementById('dual_y_div1'));
chart1.draw(data, options);
};
。
答案 1 :(得分:-1)
您的项目中是否有一个名为png的目录?如果是这样,python将尝试导入它而不是实际的模块