Import Tensorflow in spyder on mac - macos

I followed the instructions on tensorflow.org:
./conda create -n tensorflow python=2.7
source activate tensorflow
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/tensorflow-0.9.0-py2-none-any.whl --ignore-installed
pip install --upgrade $TF_BINARY_URL
When I run python in terminal, I can import tensorflow
But when I try to import tensorflow in Spyder, I got:
ImportError: No module named tensorflow
How to get tensorflow in Spyder?

I just found out that if environment is changed at the Launcher from root to tensorflow, I can install a fresh copy of Spyder in that environment. Once installed, import tensorflow works.

Related

No module named 'torch' in Jupyter Notebook but it is installed (Mac OS)

So when I try to import torch in jupyter notebook it gives the error no module named 'torch'.
I created a conda environment named "Thesis" where I work in and install my packages.
When I try these commands in my terminal it says the package is installed (see three images below):
torch1
torch2
torch3
I tried many commands to install the package:
pip install torchvision
python3 -m pip install torchvision
conda install pytorch torchvision -c pytorch
I also tried installing the package directly in the jupyter notebook itself via:
import sys
!{sys.executable} -m pip install torchvision
It at least shows something but I got the following dependency error
dependency error
I also created a kernel
ipython kernel install --name "thesis" --user
All did not help and I still receive the error in jupyter notebook.
Does somebody know how to resolve this?
I solved the problem by downloading and activating virtualenv with:
python3 -m pip install virtualenv
virtualenv <my_env_name>
source <my_env_name>/bin/activate
And getting the path in the jupyter notebook by:
import sys
print(sys.executable)
which outputs:
/Users/{username}/opt/anaconda3/bin/python
And installing the packages in the terminal via:
/Users/{username}/opt/anaconda3/bin/python -m pip install {package_name}

unable to load torchaudio even after installing

I'm trying to use torchaudio but I'm unable to import it. I have installed it and it is also visible through the pip list.
<ipython-input-6-4cf0a64f61c0> in <module>
----> 1 import torchaudio
ModuleNotFoundError: No module named 'torchaudio'
pytorch-lightning 1.2.0
torch 1.10.1
torchaudio 0.10.1
torchvision 0.11.2
WARNING: You are using pip version 21.1.2; however, version 21.3.1 is available.
You should consider upgrading via the '/usr/bin/python3 -m pip install --upgrade pip' command.
Since you are using linux and CPU, you should consider uninstalling every pytorch related packages and re-install them via:
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cpu
as shown here.
I was stuck with the same error. Tried a lot of ways to install and use torchaudio.
This was worked for me (after uninstalling existing torchaudio):
import os
!git clone https://github.com/pytorch/audio.git
os.chdir("audio")
!git checkout 632ea67
!python setup.py install

Geopandas in Google Colab

I am using Google Colab. I have installed the PyGMT. Now, I want to install the Geopandas but I got lots of errors when i type "!pip install geopandas" or "!conda install geopandas". Can you help me to install geopandas in googlecolab?
Here is my code;
from google.colab import drive
drive.mount('/content/drive')
import os
import sys
import os
sys.path.append('/usr/local/lib/python3.8/site-packages')
os.environ["GMT_LIBRARY_PATH"]="/usr/local/lib"
!wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
!chmod +x Miniconda3-latest-Linux-x86_64.sh
!bash ./Miniconda3-latest-Linux-x86_64.sh -bfp /usr/local
!conda update conda -y -q
!conda config --prepend channels conda-forge
!conda install -q -y --prefix /usr/local python=3.8 pygmt
import sys
import os
sys.path.append('/usr/local/lib/python3.8/site-packages')
os.environ["GMT_LIBRARY_PATH"]="/usr/local/lib"
!pip install geopandas
import pygmt
import pandas as pd
import geopandas
When I do !pip install geopandas and import it, it says that: ModuleNotFoundError: No module named 'pyproj._network'
have you tried using
!pip install --upgrade geopandas
don't forget to also update the other dependencies
!pip install --upgrade pyshp
!pip install --upgrade shapely
!pip install --upgrade descartes
Found it in this Google Colab tutorial, https://colab.research.google.com/drive/1We-LMiSeucESsiB1tmvL9nZrntyWsri-#scrollTo=xIXl9KBOxVKE
Hope it works,
Conda is not available in google colab by default like numpy, pandas etc is. So doing !conda install geopandas won't do any help. There's another way around it though. You CAN install conda on google colab and using it you can install other packages. Here's how:
!pip install -q condacolab
import condacolab
condacolab.install()
Then try installing with !conda install geopandas and import it using import geopandas
You can use these three lines to import geopandas in colab:
!apt install libspatialindex-dev
!pip install rtree
!pip install geopandas

Conda CMD Crashes Upon Theano Installation

Here are all the lines that I used to install theano:
# Create env.
conda create --name PyMC3 python=3.6
# Activate
activate PyMC3
# update pip
python -m pip install --upgrade pip
# Install theano reqirements
conda install numpy scipy mkl-service libpython m2w64-toolchain
# Install theano
conda install theano pygpu
I have CUDA drivers installed, which I use for tensorflow in another environment.
At the end of the installation, the CMD closes itself. Then every time I type:
activate PyMC3
It also closes / crashes.
At this time (March 14th of 2019), it seems like Theano doesn't support python 3.6, even though there is a conda package for it.
I used python 3.5 and it installs.

How to solve theano Segmentation fault?

I am running a python file which content is:
import theano.tensor as T
This gives me a Segmentation fault.
I am using anaconda.
How can this be solved?
I had the same problem after I updated scipy from version 0.17.1 to version 0.18.0
Try to create a virtual environment with conda (from Anaconda) only for theano, with the correct versions of scipy and numpy:
conda create --name theano_env theano python=2.7
or (for python 3.5):
conda create --name theano_env theano python=3.5
It solved the problem for me.

Resources