简体   繁体   中英

pycharm numpy/tensorflow error

I am importing both tf and np in pycharm. tf version of 1.6.0 and numpy version of 1.14.1. I keep running into this error. Please help -

Traceback (most recent call last):
  File "<path>PycharmProjects/testflow/testflow.py", line 1, in <module>
    import numpy as np
  File "<path>PycharmProjects/testflow/venv/lib/python3.5/site-packages/numpy/__init__.py", line 166, in <module>
    from . import random
  File "<path>/PycharmProjects/testflow/venv/lib/python3.5/site-packages/numpy/random/__init__.py", line 99, in <module>
    from .mtrand import *
  File "type.pxd", line 9, in init mtrand
ValueError: builtins.type has the wrong size, try recompiling. Expected 840, got 864

Process finished with exit code 1

The code is very simple -

import numpy as np
import tensorflow as tf

a = tf.constant([1, 2, 3], name='myname')
print (a)
with tf.Session() as sess:
    print (sess.run(a))

b = np.array([1,2,3])
print (b)

It looks as if the imports are just a little messed up from that tiny snippet. Try something like the following:

import numpy as np
from numpy import random
from numpy.random import mtrand

i = random.rand()   # Can omit the np in np.random()
j = mtrand.bytes(5)     # Can omit the np.random in np.random.mtrand.bytes(5)
print(i)
print(j)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM