The operating system is ubuntu 17.10.
https://www.tensorflow.org/install/install_linux
You have successfully installed tensorflow in Virtualenv and run it in the terminal as shown in .Specifically, after import tensorflowastf
, a simple sess.run
using tf.constant
is created.
However, while the import is successful on the jupyter notebook, the error AttributeError: module 'tensorflow' has no attribute 'constant'
appears when using tf.constant
.
I installed the jupyter notebook with pip and the connection doesn't seem to work, but I don't know what to do.
Launching jupyter notebook under Virtualenv
import tensorflow
The error will appear even on the .
pip install jupyter
under Virtualenv causes messages such as launchpadlib 1.10.5 requirements testresources, which is not installed.
.
About the first half of the question
Python imports modules by looking for names in the built-in module, then by listing the directories in sys.path.
Simply import
does not invoke a package in a different environment, which results in an error.If you really want to invoke it, you can import tensorflow
by adding a directory with the tensorflow
package to sys.path as follows:
import sys
sys.path.append('pathto/site-packages')
I'm curious about the sentence below, but have you created a file called tensorflow.py
or a directory called tensorflow
in a directory where you can search for it, such as the current directory?If you have, import tensorflow
will import that file or directory, and the original tensorflow
package will not load.
Import succeeds on jupyter notebook, but
The path of the imported module can be displayed using the following command, so you should check it.
print(tensorflow.__path__)
About the second half of the question
If you follow the documentation in the question, you are configured to use the installed module as follows:
virtualenv --system-site-packages-python3
However, with Ubuntu 18.04, this will cause the same problem as the one mentioned in the question.GitHub pip also has a problem.Ubuntu 17.10 appears to be experiencing the same problem.
In order to eliminate this error first, you can configure the virtual environment without the installed modules.
virtualenv-p python3
© 2024 OneMinuteCode. All rights reserved.