简体   繁体   English

在Pycharm中使用Tensorflow virtualenv时出错(Ubuntu 16)

[英]Error using Tensorflow virtualenv in Pycharm (Ubuntu 16)

I've installed Tensorflow within a virtual environment on my machine. 我在我的机器上的虚拟环境中安装了Tensorflow。 It works from the command line but when I try to run it from Pycharm it gives the following error: Pycharm Console Output 它从命令行工作,但当我尝试从Pycharm运行它时,它会出现以下错误: Pycharm控制台输出

The project interpreter is set to virtualenv at ~/tensorflow and for the interpreter paths the following ones are set: 项目解释器在〜/ tensorflow设置为virtualenv,对于解释器路径,设置以下设置:

  • /home/user/tensorflow/lib/python3.5 /home/user/tensorflow/lib/python3.5
  • /home/user/tensorflow/lib/python3.5/plat-x86_64-linux-gpu /home/user/tensorflow/lib/python3.5/plat-x86_64-linux-gpu
  • /home/user/tensorflow/lib/python3.5/lib-dynload /home/user/tensorflow/lib/python3.5/lib-dynload
  • /usr/lib/python3.5 /usr/lib/python3.5
  • /usr/lib/python3.5/plat-x86_64-linux-gnu /usr/lib/python3.5/plat-x86_64-linux-gnu
  • /home/user/tensorflow/lib/python3.5/site-packages /home/user/tensorflow/lib/python3.5/site-packages
  • /usr/lib/python3.5/site-packages /usr/lib/python3.5/site-packages
  • /usr/local/lib/python3.5/dist-packages /usr/local/lib/python3.5/dist-packages
  • /usr/lib/python3/dist-packages / usr / lib目录/ python3 / DIST-包

The code (from a tutorial) I've tried to run is the following: 我尝试运行的代码(来自教程)如下:

    import tensorflow as tf

    x = tf.constant(35, name='x')
    y = tf.Variable(x + 5, name='y')

    model = tf.global_variables_initializer()

    with tf.Session() as session:
    session.run(model)
    print(session.run(y))

So what could this error be related to? 那么这个错误可能与什么有关呢?

Ok, so it works if you call Pycharm from the terminal. 好的,如果你从终端调用Pycharm它就可以了。 I guess that the terminal context is given to pycharm the moment you load it from the command line. 我想终端上下文是从命令行加载它时给pycharm的。 (Pycharm is executed from the command line by executing the pycharm.sh script. If you don't know how where it is then type 'locate pycharm.sh') (通过执行pycharm.sh脚本从命令行执行Pycharm。如果你不知道它在哪里,那么输入'locate pycharm.sh')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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