您的位置:首页 > 编程语言 > Python开发

paddle paddle 运行 Fatal Python error: PyThreadState_Get: no current thread

2018-03-26 20:44 671 查看

使用paddlepaddle时运行tutorial代码:

import paddle.v2 as paddle

# Initialize PaddlePaddle.
paddle.init(use_gpu=False, trainer_count=1)

# Configure the neural network.
x = paddle.layer.data(name='x', type=paddle.data_type.dense_vector(13))
y_predict = paddle.layer.fc(input=x, size=1, act=paddle.activation.Linear())

with open('fit_a_line.tar', 'r') as f:
parameters = paddle.parameters.Parameters.from_tar(f)

# Infer using provided test data.
probs = paddle.infer(
output_layer=y_predict, parameters=parameters,
input=[item for item in paddle.dataset.uci_housing.test()()])

for i in xrange(len(probs)):
print 'Predicted price: ${:,.2f}'.format(probs[i][0] * 1000)


出现:

Fatal Python error: PyThreadState_Get: no current thread

是由于brew的python和anaconda的python冲突。

解决方法:

1.执行

otool -L /anaconda2/lib/python2.7/site-packages/py_paddle/_swig_paddle.so

得到:

/anaconda2/lib/python2.7/site-packages/py_paddle/_swig_paddle.so

/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1445.12.0)

/System/Library/Frameworks/Security.framework/Versions/A/Security (compatibility version 1.0.0, current version 58286.20.16)

/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.0)

/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.0)

/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.0.0)

发现并没有/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/Python 这个路径。

2.执行

install_name_tool -change /usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/Python /anaconda/lib/libpython2.7.dylib /anaconda/lib/python2.7/site-packages/py_paddle/_swig_paddle.so

此时运行paddlepaddle的tutorial,成功。

I0326 20:41:27.464560 3940180928 Util.cpp:166] commandline: –use_gpu=False –trainer_count=1

Cache file /Users/suiyang/.cache/paddle/dataset/uci_housing/housing.data not found, downloading https://archive.ics.uci.edu/ml/machine-learning-databases/housing/housing.data

[==== ]

[======== ]

[============ ]

[================ ]

[==================== ]

[========================= ]

[============================= ]

[================================= ]

[===================================== ]

[===================
1c6f3
====================== ]

[============================================= ]

[==================================================]Predicted price: 12,316.63Predictedprice:12,316.63Predictedprice:13,830.34

Predicted price: 11,499.34Predictedprice:11,499.34Predictedprice:17,395.05

Predicted price: 13,317.67Predictedprice:13,317.67Predictedprice:16,834.08

Predicted price: 16,632.04Predictedprice:16,632.04Predictedprice:15,384.20

Predicted price: 7,697.38Predictedprice:7,697.38Predictedprice:13,657.83

Predicted price: 6,329.62Predictedprice:6,329.62Predictedprice:12,153.18

Predicted price: 13,890.60Predictedprice:13,890.60Predictedprice:11,367.41

Predicted price: 13,269.13Predictedprice:13,269.13Predictedprice:14,979.35

Predicted price: 17,539.03Predictedprice:17,539.03Predictedprice:16,686.41

Predicted price: 16,810.74Predictedprice:16,810.74Predictedprice:13,620.53

Predicted price: 14,720.09Predictedprice:14,720.09Predictedprice:12,533.42

Predicted price: 15,835.49Predictedprice:15,835.49Predictedprice:16,064.76

Predicted price: 14,566.97Predictedprice:14,566.97Predictedprice:13,783.11

Predicted price: 16,211.73Predictedprice:16,211.73Predictedprice:16,362.79

Predicted price: 18,183.92Predictedprice:18,183.92Predictedprice:16,298.03

Predicted price: 16,084.58Predictedprice:16,084.58Predictedprice:14,406.07

Predicted price: 15,309.62Predictedprice:15,309.62Predictedprice:12,104.60

Predicted price: 9,865.44Predictedprice:9,865.44Predictedprice:14,116.36

Predicted price: 14,552.37Predictedprice:14,552.37Predictedprice:16,381.32

Predicted price: 16,992.90Predictedprice:16,992.90Predictedprice:16,722.93

Predicted price: 13,468.48Predictedprice:13,468.48Predictedprice:13,622.97

Predicted price: 16,512.31Predictedprice:16,512.31Predictedprice:17,004.60

Predicted price: 16,492.97Predictedprice:16,492.97Predictedprice:16,179.70

Predicted price: 15,989.17Predictedprice:15,989.17Predictedprice:17,289.17

Predicted price: 16,975.07Predictedprice:16,975.07Predictedprice:18,950.22

Predicted price: 15,513.54Predictedprice:15,513.54Predictedprice:15,652.08

Predicted price: 14,162.51Predictedprice:14,162.51Predictedprice:14,665.31

Predicted price: 16,724.47Predictedprice:16,724.47Predictedprice:17,369.51

Predicted price: 17,330.55Predictedprice:17,330.55Predictedprice:17,923.71

Predicted price: 18,018.71Predictedprice:18,018.71Predictedprice:19,392.96

Predicted price: 18,379.00Predictedprice:18,379.00Predictedprice:17,187.61

Predicted price: 14,920.71Predictedprice:14,920.71Predictedprice:15,435.08

Predicted price: 16,458.07Predictedprice:16,458.07Predictedprice:17,390.93

Predicted price: 17,520.05Predictedprice:17,520.05Predictedprice:18,763.72

Predicted price: 18,698.70Predictedprice:18,698.70Predictedprice:20,425.67

Predicted price: 15,431.77Predictedprice:15,431.77Predictedprice:14,803.56

Predicted price: 17,336.69Predictedprice:17,336.69Predictedprice:13,052.34

Predicted price: 16,874.23Predictedprice:16,874.23Predictedprice:18,547.62

Predicted price: 19,574.30Predictedprice:19,574.30Predictedprice:21,303.89

Predicted price: 22,053.60Predictedprice:22,053.60Predictedprice:18,862.40

Predicted price: 17,969.15Predictedprice:17,969.15Predictedprice:19,496.96

Predicted price: 17,676.56Predictedprice:17,676.56Predictedprice:18,699.87

Predicted price: 14,520.48Predictedprice:14,520.48Predictedprice:12,410.05

Predicted price: 9,987.12Predictedprice:9,987.12Predictedprice:15,381.11

Predicted price: 16,906.17Predictedprice:16,906.17Predictedprice:21,538.57

Predicted price: 21,566.74Predictedprice:21,566.74Predictedprice:19,905.33

Predicted price: 17,938.98Predictedprice:17,938.98Predictedprice:20,776.08

Predicted price: 21,715.28Predictedprice:21,715.28Predictedprice:20,169.60

Predicted price: 21,148.05Predictedprice:21,148.05Predictedprice:22,589.09

Predicted price: 21,913.31Predictedprice:21,913.31Predictedprice:24,388.41

Predicted price: 23,748.72Predictedprice:23,748.72Predictedprice:22,013.94

[Finished in 8.5s]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐