Matplotlib现在挂起我升级到塞拉利昂。
根据我的运行方式,行为会有所不同。
在文件中(在ipython中运行%run <filename>
或从终端运行python <file name>
):
终端将挂起导入(import matplotlib.pyplot as plt
),我得到的只是在我的码头中弹跳的小火箭图标。
直接来自ipython :
我可以导入它并显示一个情节,但是一旦我尝试关闭图形窗口它就会挂起。从基本python shell内部执行此操作没有此问题。所以它似乎在交互模式下运行也会导致挂起。
有没有人经历过类似的事情?
python版本:3.5.2
matplotlib版本:1.5.1
后端:MacOSX
OSX:10.12.2
切换到TkAgg后端将显示图形窗口,但它将在绘图时挂起(在交互模式下)。
注意
设置虚拟环境以使用TkAgg后端运行python 2.7按预期工作
答案 0 :(得分:-1)
似乎是一个缓存问题:
运行:
public function index()
{
$validator = Validator::make(Input::all(), [
'image' => 'required|image|max:' . (1024 * 3),
]);
if ($validator->fails()) {
$messages = $validator->messages();
echo json_encode([
'return' => 'error',
'message' => $messages->first('image')
]);
} else {
$originalName = Input::file('image')->getClientOriginalName();
$extension = Input::file('image')->getClientOriginalExtension();
$size = Input::file('image')->getSize();
$type = (Auth::check()) ? Auth::user()->default_image_privacy : 'public';
$adult = Input::has('adult') ? Input::get('adult') : 0;
$adult = ($adult != 1) ? 0 : 1;
$status = (Settings::get('auto_approve_images') == 1) ? 'active' : 'pending';
$image = new Image;
$image->user_id = (Auth::check()) ? Auth::user()->id : 0;
$image->file_name = $originalName;
$image->file_extn = $extension;
$image->file_size = $size;
$image->status = $status;
$image->type = $type;
$image->adult = $adult;
$image->ip = Net::getIP();
$image->save();
$imageFolder = floor($image->id / 1000) + 1;
$imageFolder = md5($imageFolder);
$imageFolder = substr($imageFolder, 1, 10);
$imageFolder = trim($imageFolder);
$image->folder = $imageFolder;
$image->save();
$destinationPath = public_path('uploads/' . $imageFolder);
$fileName = $image->id . '.' . $extension;
Input::file('image')->move($destinationPath, $fileName);
$destinationPathThumb = public_path('thumb/' . $imageFolder);
if (! File::isDirectory($destinationPathThumb)) {
File::makeDirectory($destinationPathThumb, 0755, true);
}
$fileNameThumb = $image->id . '.' . $extension;
$thumbWidth = (int) Settings::get('thumb_width');
$thumbWidth = ($thumbWidth < 80) ? 100 : $thumbWidth;
$thumbHeight = (int) Settings::get('thumb_height');
$thumbHeight = ($thumbHeight < 80) ? 100 : $thumbHeight;
Thumb::create($destinationPath . '/' . $fileName, $destinationPathThumb . '/' . $fileNameThumb, $thumbWidth, $thumbHeight);
$fileNameMed = $image->id . '_md.' . $extension;
$medWidth = 700;
$medHeight = 600;
Thumb::create($destinationPath . '/' . $fileName, $destinationPathThumb . '/' . $fileNameMed, $medWidth, $medHeight);
echo json_encode([
'return' => 'success',
'imageUid' => $image->id
]);
}
exit();
}
public function link()
{
$validator = Validator::make(Input::all(), [
'url' => 'required|url',
]);
if ($validator->fails()) {
return Redirect::back()->withErrors($validator);
} else {
$originalName = basename(Input::get('url'));
$nameSplit = explode('.', $originalName);
$extension = $nameSplit[count($nameSplit) - 1];
if (! in_array($extension, ['jpeg', 'jpg', 'png', 'bmp', 'gif'])) {
return Redirect::back()->withErrors($validator);
}
$type = (Auth::check()) ? Auth::user()->default_image_privacy : 'public';
$adult = Input::has('adult') ? Input::get('adult') : 0;
$adult = ($adult != 1) ? 0 : 1;
$image = new Image;
$image->user_id = (Auth::check()) ? Auth::user()->id : 0;
$image->file_name = $originalName;
$image->file_extn = $extension;
$image->status = 'active';
$image->type = $type;
$image->adult = $adult;
$image->ip = Net::getIP();
$image->save();
$imageFolder = floor($image->id / 1000) + 1;
$imageFolder = md5($imageFolder);
$imageFolder = substr($imageFolder, 1, 10);
$imageFolder = trim($imageFolder);
$image->folder = $imageFolder;
$image->save();
$destinationPath = public_path('uploads/' . $imageFolder);
$fileName = $image->id . '.' . $extension;
File::copy(Input::get('url'), $destinationPath . '/' . $fileName);
$size = File::size($destinationPath . '/' . $fileName);
$image->file_size = $size;
$image->save();
$destinationPathThumb = public_path('thumb/' . $imageFolder);
if (! File::isDirectory($destinationPathThumb)) {
File::makeDirectory($destinationPathThumb, 0755, true);
}
$fileNameThumb = $image->id . '.' . $extension;
$thumbWidth = (int) Settings::get('thumb_width');
$thumbWidth = ($thumbWidth < 80) ? 100 : $thumbWidth;
$thumbHeight = (int) Settings::get('thumb_height');
$thumbHeight = ($thumbHeight < 80) ? 100 : $thumbHeight;
Thumb::create($destinationPath . '/' . $fileName, $destinationPathThumb . '/' . $fileNameThumb, $thumbWidth, $thumbHeight);
$fileNameMed = $image->id . '_md.' . $extension;
$medWidth = 700;
$medHeight = 600;
Thumb::create($destinationPath . '/' . $fileName, $destinationPathThumb . '/' . $fileNameMed, $medWidth, $medHeight);
return Redirect::to('/upload/success?id=' . $image->id);
}
}
public function success()
{
if (! Input::has('id')) {
return Redirect::to('/');
}
$imageIdArr = explode(',', Input::get('id'));
$imageIdArr = array_where($imageIdArr, function($key, $value)
{
return is_numeric($value);
});
$imageIdArr = array_unique($imageIdArr);
if (empty($imageIdArr)) {
return Redirect::to('/');
}
$imagesInfo = Image::whereIn('id', $imageIdArr)->get();
return View::make('upload.success', [
'imagesInfo' => $imagesInfo,
]);
}
解决了问题(这里讨论了同样的问题:import matplotlib.pyplot hangs,但症状有点不同)