ImportError:libcudart.so.8.0:cannot open shared object file:No such file or directory - tensorflow

I used the spyder or terminal to run the mnist_deep.py program , it can run normally, but when i run the program using pycharm, it will cause an error.The Project Interpreter is 2.7.12(~/anaconda2/bin/python).
Error Type:
ImportError:libcudart.so.8.0:cannot open shared object file:No such file or directory
Error importing tensorflow.Unless you are using bazel,you should not try to import tensorflow from its source directory;please exit the tensorflow source tree,and relaunch your python interpreter from there

It's preferable to do a system-wide configuration instead of editing ~/.bashrc. Create a .conf file in /etc/ld.so.conf.d/:
sudo nano /etc/ld.so.conf.d/nvidia.conf
Add this:
/usr/local/cuda-8.0/lib64
/usr/local/cuda-8.0/lib # you probably don't need this line; check
# if the directory exists
Then run sudo ldconfig. Hope this brings you joy.

In my case, I had installed tensorflow-gpu on a machine without a GPU.
Uninstalling it fixed the problem
pip uninstall tensorflow-gpu
pip install tensorflow --ignore-installed
Without the 2nd step, I was getting an error No module named tensorflow (ref)

Related

Re use the venv that's already created in a given folder

I used to keep my projects in a HDD and recently changed my pc. Now when I try to activate the virtual environment using:
.\wfa_virtual\Scripts\activate
it activates the environment but when I try to install a new package using the command:
pip install --upgrade google-cloud-bigquery
it gives me error saying:
Fatal error in launcher: Unable to create process using '"f:\yoptima_bcup\yoptima_curr\universaldashboard\workflowautomationnew\wfa_instancebcup\workflow-automation\workflowautomation\wfa_virtual\scripts\python.exe"
The only change in the folder location is D drive from f drive, how can I let my venv know that the location has been changed?
Edit: I have also tried updating:
VIRTUAL_ENV="D:\yoptima_bcup\Yoptima_Curr\universalDashboard\workFlowAutomationNew\wfa_instanceBcup\workflow-automation\workFlowAutomation\wfa_venv" in activate file and also:
set VIRTUAL_ENV=D:\yoptima_bcup\Yoptima_Curr\universalDashboard\workFlowAutomationNew\wfa_instanceBcup\workflow-automation\workFlowAutomation\wfa_venv
in activate.bat file but no effect.

tensor flow install problems [duplicate]

I'm trying to use pip to install a package. I try to run pip install from the Python shell, but I get a SyntaxError. Why do I get this error? How do I use pip to install the package?
>>> pip install selenium
^
SyntaxError: invalid syntax
pip is run from the command line, not the Python interpreter. It is a program that installs modules, so you can use them from Python. Once you have installed the module, then you can open the Python shell and do import selenium.
The Python shell is not a command line, it is an interactive interpreter. You type Python code into it, not commands.
Use the command line, not the Python shell (DOS, PowerShell in Windows).
C:\Program Files\Python2.7\Scripts> pip install XYZ
If you installed Python into your PATH using the latest installers, you don't need to be in that folder to run pip
Terminal in Mac or Linux
$ pip install XYZ
As #sinoroc suggested correct way of installing a package via pip is using separate process since pip may cause closing a thread or may require a restart of interpreter to load new installed package so this is the right way of using the API: subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'SomeProject']) but since Python allows to access internal API and you know what you're using the API for you may want to use internal API anyway eg. if you're building own GUI package manager with alternative resourcess like https://www.lfd.uci.edu/~gohlke/pythonlibs/
Following soulution is OUT OF DATE, instead of downvoting suggest updates. see https://github.com/pypa/pip/issues/7498 for reference.
UPDATE: Since pip version 10.x there is no more get_installed_distributions() or main method under import pip instead use import pip._internal as pip.
UPDATE ca. v.18 get_installed_distributions() has been removed. Instead you may use generator freeze like this:
from pip._internal.operations.freeze import freeze
print([package for package in freeze()])
# eg output ['pip==19.0.3']
If you want to use pip inside the Python interpreter, try this:
import pip
package_names=['selenium', 'requests'] #packages to install
pip.main(['install'] + package_names + ['--upgrade'])
# --upgrade to install or update existing packages
If you need to update every installed package, use following:
import pip
for i in pip.get_installed_distributions():
pip.main(['install', i.key, '--upgrade'])
If you want to stop installing other packages if any installation fails, use it in one single pip.main([]) call:
import pip
package_names = [i.key for i in pip.get_installed_distributions()]
pip.main(['install'] + package_names + ['--upgrade'])
Note: When you install from list in file with -r / --requirement parameter you do NOT need open() function.
pip.main(['install', '-r', 'filename'])
Warning: Some parameters as simple --help may cause python interpreter to stop.
Curiosity: By using pip.exe you actually use python interpreter and pip module anyway. If you unpack pip.exe or pip3.exe regardless it's python 2.x or 3.x, inside is the SAME single file __main__.py:
# -*- coding: utf-8 -*-
import re
import sys
from pip import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(main())
To run pip in Python 3.x, just follow the instructions on Python's page: Installing Python Modules.
python -m pip install SomePackage
Note that this is run from the command line and not the python shell (the reason for syntax error in the original question).
I installed python and when I run pip command it used to throw me an error like shown in pic below.
Make Sure pip path is added in environmental variables. For me, the python and pip installation path is::
Python: C:\Users\fhhz\AppData\Local\Programs\Python\Python38\
pip: C:\Users\fhhz\AppData\Local\Programs\Python\Python38\Scripts
Both these paths were added to path in environmental variables.
Now Open a new cmd window and type pip, you should be seeing a screen as below.
Now type pip install <<package-name>>. Here I'm installing package spyder so my command line statement will be as pip install spyder and here goes my running screen..
and I hope we are done with this!!
you need to type it in cmd not in the IDLE. becuse IDLE is not an command prompt if you want to install something from IDLE type this
>>>from pip.__main__ import _main as main
>>>main(#args splitted by space in list example:['install', 'requests'])
this is calling pip like pip <commands> in terminal. The commands will be seperated by spaces that you are doing there to.
If you are doing it from command line,
try -
python -m pip install selenium
or (for Python3 and above)
python3 -m pip install selenium

TensorFlow Object Detection tutorial program can't find string_int_label_map_pb2

I'm trying to install TensorFlow Object Detection on my PC which is Windows10, after finished all the installation steps, I tied to run tutorial program, but I told me there is a import problem
ImportError: cannot import name 'string_int_label_map_pb2'
I have run the
protoc object_detection/protos/*.proto --python_out=.
My python is 3.6.2, protoc version is 3.4.0
Well, I have run the command in CMD without "python" at front, after I add python it works
You need to set the PYTHONPATH variables and point them to the object_detection folder. You can run the below command:
set PYTHONPATH=path\to\object_detection\models;path\to\object_detection\models\research;path\to\object_detection\models\research\slim;path\to\object_detection\models\research\object_detection
replace the "path\to\" with your actual path. After you have done the path setting, restart the jupyter notebook and try runnning again. You should not see the error. Hope it helps.

tensorboard: command not found

I installed TensorFlow on my MacBook Pro 10.12.5 from source code by steps described here.
https://www.tensorflow.org/install/install_sources
TensorFlow itself works well but I cannot run TensorBoard.
It seems tensorboard is not installed properly.
When I try running tensorboard --logdir=... it says -bash: tensorboard: command not found. And locate tensorboard returns empty.
Do I need any additional step to install tensorboard?
You could call tensorboard as a python module like this:
python3 -m tensorboard.main --logdir=~/my/training/dir
or add this to your .profile
alias tensorboard='python3 -m tensorboard.main'
If no other methods work then try this one. It may help you.
1. check the location of Tensorflow
pip show tensorflow
It will show output something like this.
...
Name: tensorflow
Version: 1.4.0
Location: /home/abc/xy/.local/lib/python2.7/site-packages
...
2. Go to that location you get from the above output.
cd /home/abc/xy/.local/lib/python2.7/site-packages
There you can see a directory named tensorboard.
cd tensorboard
3. There must be a file named 'main.py'.
4. Execute the following command to launch the tensorboard.
python main.py --logdir=/path/to/log_file/
If you installed Tensorflow with Virtualenv, then first Check whether you have activated the tensorflow envirnoment or not
If you have activated the tensorflow session then your command prompt will look like this :
If not, Write the below command and try running tensorboard again.
source ~/tensorflow/bin/activate
Run this command:
python3 -m tensorboard.main --logdir=logdir
To run directory you can use,
Change =logdir to ="dir/TensorFlow"
(Directory path)
What version of Tensorflow are you running? Older versions don't include Tensorboard.
If you do have a newer version, I see you are using OSX, which apparently caused some problems for other people: https://github.com/tensorflow/tensorflow/issues/2115 Check this page to fix it!
As a MacPorts user, I'm used to running things from out of the path
/opt/local/bin. When you install a python package via MacPorts, that's
where the executables go --- even if they're just symbolic links to
files to a main python repository in
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/
pip installs things into the latter directory, but apparently does NOT
add the symbolic link to /opt/local/bin
This has never been an issue (or even come up) for me before, because
I've only used pip to install (non-executable) packages which load
from within python. In conclusion, there is a
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/tensorboard
This is a pip / MacPorts-SOP mismatch / user error*, and nothing to do
with tensorboard in particular. Please close this issue. Thanks for
your help.
*my 'locate' database was in the process of updating but hadn't completed
Quickest solution -
echo "alias tensorboard='python3 -m tensorboard.main'" >> ~/.bash_profile
After adding this to your .bash_profile you can use
tensorboard --logdir=/path
If you are using pycharm in windows environment this may help:
python -m tensorboard.main --logdir=logs

How do I install TensorFlow's tensorboard?

How do I install TensorFlow's tensorboard?
The steps to install Tensorflow are here: https://www.tensorflow.org/install/
For example, on Linux for CPU-only (no GPU), you would type this command:
pip install -U pip
pip install tensorflow
Since TensorFlow depends on TensorBoard, running the following command should not be necessary:
pip install tensorboard
Try typing which tensorboard in your terminal. It should exist if you installed with pip as mentioned in the tensorboard README (although the documentation doesn't tell you that you can now launch tensorboard without doing anything else).
You need to give it a log directory. If you are in the directory where you saved your graph, you can launch it from your terminal with something like:
tensorboard --logdir .
or more generally:
tensorboard --logdir /path/to/log/directory
for any log directory.
Then open your favorite web browser and type in localhost:6006 to connect.
That should get you started. As for logging anything useful in your training process, you need to use the TensorFlow Summary API. You can also use the TensorBoard callback in Keras.
If your Tensorflow install is located here:
/usr/local/lib/python2.7/dist-packages/tensorflow
then the python command to launch Tensorboard is:
$ python /usr/local/lib/python2.7/dist-packages/tensorflow/tensorboard/tensorboard.py --logdir=/home/user/Documents/.../logdir
The installation from pip allows you to use:
$ tensorboard --logdir=/home/user/Documents/.../logdir
It may be helpful to make an alias for it.
Install and find your tensorboard location:
pip install tensorboard
pip show tensorboard
Add the following alias in .bashrc:
alias tensorboard='python pathShownByPip/tensorboard/main.py'
Open another terminal or run exec bash.
For Windows users, cd into pathShownByPip\tensorboard and run python main.py from there.
For Python 3.x, use pip3 instead of pip, and don't forget to use python3 in the alias.
TensorBoard isn't a separate component. TensorBoard comes packaged with TensorFlow.
Adding this just for the sake of completeness of this question (some questions may get closed as duplicate of this one).
I usually use user mode for pip ie. pip install --user even if instructions assume root mode. That way, my tensorboard installation was in ~/.local/bin/tensorboard, and it was not in my path (which shouldn't be ideal either). So I was not able to access it.
In this case, running
sudo ln -s ~/.local/bin/tensorboard /usr/bin
should fix it.
pip install tensorflow.tensorboard # install tensorboard
pip show tensorflow.tensorboard
# Location: c:\users\<name>\appdata\roaming\python\python35\site-packages
# now just run tensorboard as:
python c:\users\<name>\appdata\roaming\python\python35\site-packages\tensorboard\main.py --logdir=<logidr>
If you're using the anaconda distribution of Python, then simply do:
$❯ conda install -c conda-forge tensorboard
or
$❯ conda install -c anaconda tensorboard
Also, you can have a look at various builds by search the packages repo by:
$❯ anaconda search -t conda tensorboard
which would list the channels and the corresponding builds, the supported OS, Python versions etc.,
The pip package you are looking for is tensorflow-tensorboard developed by Google.
If you installed TensorFlow using pip, then the location of TensorBoard can be retrieved by issuing the command which tensorboard on the terminal. You can then edit the TensorBoard file, if necessary.
It is better not to mix up the virtual environments or perform installation on the root directory. Steps I took for hassle free installation are as below. I used conda for installing all my dependencies instead of pip. I'm answering with extra details, because when I tried to install tensor board and tensor flow on my root env, it messed up.
Create a virtual env
conda create --name my_env python=3.6
Activate virtual environment
source activate my_env
Install basic required modules
conda install pandas
conda install tensorflow
Install tensor board
conda install -c condo-forge tensor board
Hope that helps
I have a local install of tensorflow 1.15.0 (with tensorboard obviously included) on MacOS.
For me, the path to the relevant file within my user directory is Library/Python/3.7/lib/python/site-packages/tensorboard/main.py. So, which does not work for me, but you have to look for the file named main.py, which is weird since it apparently is named something else for other users.