Pytorch module not found - python

I'm using Python 3.6, and trying to use Pytorch. I've uninstalled it using pip3, and re-installed it
Hugos-MacBook-Pro-2:project hugokitano$ pip3 install torch
Requirement already satisfied: torch in /usr/local/lib/python3.7/site-packages (1.3.1)
Requirement already satisfied: numpy in /Users/hugokitano/Library/Python/3.7/lib/python/site-packages (from torch) (1.17.2)
However, when I try to import torch, the module is not found. I've also tried to install via conda, running
conda install pytorch torchvision -c pytorch
and it was successful, installing to
environment location: /Users/hugokitano/anaconda
However, "import torch" still doesn't work. Any thoughts? Thanks!

It is wise to use environments instead of installs packages on your base. Try do the following:
conda create -n deep7 -c pytorch python=3.7 pytorch torchvision
conda activate deep7
python -c "import torch"
We have created an environment with name deep7, we use pytorch channel to install pytorch in Python 3.7. After that we activate the environment and test if the import works. If it did you will see no error.
To use pytorch, you will have to activate your environment:
conda activate deep7 and to deactivate conda deactivate. You can add libraries with conda install -n deep7 <package name>
Happy coding
BTW: if you want Python 3.6, do the same, change all the 7 above to 6 :)

Try to update conda and install it. It weirdly fixed my issue.
conda update conda

Related

installing pytorch to one conda evnironment removes existing installation from other conda environments

The pip was installed per each environment and which pip returns proper(and different) location for different conda environments.
I am not using any external scripts for the installation. It's vanilla pip install and also tried python -m pip install. Also tried to install with conda. In all of these cases, installing it for env1 will uninstall it from env2 and vice versa. No matter from which env I am installing, all envs will use the same version that was installed last.
Not sure if it's relevant, but I am using WSL2.
What could go wrong? What else should I check?
I still have no idea what is causing this behavior but at least found a workaround - using pip --ignore-installed option:
conda activate your_target_env
pip install --ignore-installed torch torchvision torchaudio
This will not uninstall other versions of pytorch installed inside other conda environments. And both environments will work with their versions of pytorch.

How should I install and import simpletransformers?

I have been using the following conda & python verison:
conda version : 4.6.14
conda-build version : 3.17.8
python version : 3.7.3.final.0
I installed simpletransformers in the following manner:
conda create -n simpletransformers python pandas tqdm
conda activate simpletransformers
conda install pytorch cpuonly -c pytorch
conda install -c anaconda scipy
conda install -c anaconda scikit-learn
pip install transformers
pip install seqeval
pip install tensorboardx
pip install simpletransformers
After doing so, I've been trying to import the classification model without much luck:
import simpletransformers
I get the following error:
ModuleNotFoundError: No module named 'simpletransformers'
Can someone point out where I'm going wrong? I'm using PyCharm as my IDE.
The setup docs work for me on Mac and Ubuntu using Anaconda:
Install Anaconda or Miniconda
Create a new virtual python 3.7 environment and install pandas and tqdm
conda create -n simplet python=3.7 pandas tqdm
conda activate simplet
PyTorch
3 a. GPU (use_cuda=True in your model): conda install pytorch cudatoolkit=10.1 -c pytorch
3 b. CPU (use_cuda=False in your model): conda install pytorch cpuonly -c pytorch
If you want to use fp16 training on an NVIDIA GPU install apex (don't use pip)
Install simpletransformers.
pip install simpletransformers
Download the .whl file from "https://pypi.org/project/simpletransformers/#files"
Open command prompt
type pip install "path/simpletransformers-0.13.2-py3-none-any.whl" and hit enter
Check whether the package gets installed.
Note that simpletransformers requires Python '>=3.6'
Whenever I have a package that is not available via Anaconda Cloud, i.e., I have to install from PyPI or GitHub, then I create a YAML environment definition for it. This follows the best practices enumerated in "Using Pip in a Conda Environment".
The advantage of a YAML is that it allows Conda to solve for everything at once and it lets one treat envs as immutable objects (i.e., if you need to alter the env, edit the YAML and recreate). This helps avoid the mess that inevitably seems to result from running a series of conda install, pip install, or conda update commands.
For me this is a multi-stage process, but it has been a reliable workflow for me:
Workflow for Mixed Conda-PyPI Environments
Look at the setup.py or requirements.txt of the non-Conda package. Here it is for simpletransformers.
For each requirement, check Anaconda Cloud (or conda search) to see if it is available as a Conda package.
If it is available, add it to the YAML file as a (non-pip) dependency. This ensures that everything that can come from Conda does.
Also, keep track of the channels that these packages come from. Note, I will not use a private channel I am unfamiliar with. In this case pytorch, conda-forge, and defaults (i.e., anaconda) suffice.
Include the packages that are PyPI-only under the pip section of the YAML, including the main package of interest (i.e., simpletransformers). Technically, you don't need to include the other dependencies, since pip will pull them in automatically, but I like to keep them explicit so that if I ever update the YAML I might check again if someone ported the PyPI packages to Conda Forge.
Create the env using the YAML
conda env create -n st_env -f simpletransformers.yaml
Check to see if any additional packages were implicitly pulled in as dependencies from PyPI, but were actually available through Conda. Edit the YAML to put these in the Conda dependencies section. In this case, keras is apparently also needed.
Remove the env and recreate using the updated maximally Conda version.
Most important: never change the env except through editing the YAML.
YAML for SimpleTransformers Environment
simpletransformers.yaml
name: st_env
channels:
- pytorch
- conda-forge
- defaults
dependencies:
- python=3.7
- pandas
- tqdm
- cpuonly
- pytorch
- transformers
- scipy
- scikit-learn
- requests
- tensorboardx
- keras
- pip
- pip:
- seqeval
- simpletransformers
Install with
conda env create -n st_env -f simpletransformers.yaml
If you have pip installed in your environment, just do hit a pip install simpletransformers in your terminal or If you're using jupyter notebook/colab, etc. then paste !pip install simpletransformers in your first cell and run it.
Then import simpletransformers
import simpletransformers

How to install fbprophet for Python 3.7 (anaconda distribution)

I attempted to use fbprophet for time series analysis using Python.
I ran from fbprophet import Prophet but got No module named 'fbprophet'
I think fbprophet is not part of packages that comes with anaconda distribution
I went ahead to install fbprophet but got this error message No module named 'fbprophet'
I am on Windows 10, 64 bits
I install anaconda distribution of anaconda 3.7
I have ran conda install -c conda-forge fbprophet and conda install -c conda-forge/label/cf201901 fbprophet on my anaconda prompt which it rolled endlessly
I have also ran pip install fbprohet which did not work as well
I ran pip list which worked but prophet or fbprophet not among the list
I have searched this site for relevant questions and tried all what I clues I got in it but did not work for me.
Option 1
conda install -n [NameOfVEnv] -c conda-forge fbprophet
Where -c stands for "channel" which is
the locations where Navigator and conda look for packages. (Source)
and -n for "Name of environment".
I just tried here (on CentOS 7) and it worked fine.
Option 2
An alternative, if one is using Windows 10, is to access Anaconda Prompt for the environment that you are working with as admin:
And run
conda install -c conda-forge fbprophet
I just tried here (on Windows 10 64-bit) and it worked fine.
Option 3
Prophet is on PyPI, so you can use pip to install it (Source)
# bash
# Install pystan with pip before using pip to install fbprophet
$ pip install pystan
$
$ pip install fbprophet
You may need to install dependencies (in both options), but it asks you in the prompt window. If it appears, you will need to enter Y.
I installed this way:
pip install pystan==2.19.1.1
then:
pip install prophet
It seems that currently pystan version 3 is not working properly.
(Tested on MacOS)
You can check this official github link where the detailed steps for installation is given. This library is supported only in Python 3.
Open cmd, run this command -
pip install pystan==2.19.1.1
Then run this-
pip install prophet
First install
pip install httpstan
Then Install
pip install pystan
Then Install
pip install fbprophet
I had the same issue, but none of the answers mentioned here worked (Windows 10 machine). What worked was the following:
conda config --add channels conda-forge
conda install anaconda
Above step took almost 25 hours for me. Do above only if you get this error "The environment is inconsistent, please check the package plan carefully"
pip install pystan==2.19.1.1
conda install python=3.8 (fbprophet did not work on Python 3.9)
conda install numpy=1.19.0
conda install fbprophet=0.7.1
you just search the wrong letter, please enter pip search fbprophet,in the way, i can get two
fbprophet did not work on Python 3.9
It is a very important information, after downgrading Python from 3.9 to 3.8, I use 'conda install fbprophet' install fbprophet successfully
Use conda install gcc to set up gcc. The easiest way to install Prophet is through conda-forge: conda install -c conda-forge prophet.

ModuleNotFoundError: No module named 'imblearn'

I tried running the following code:
from imblearn import under_sampling, over_sampling
from imblearn.over_sampling import SMOTE
sm = SMOTE(random_state=12, ratio = 1.0)
x_SMOTE, y_SMOTE = sm.fit_sample(X, y)
which gives me the error message:
ModuleNotFoundError: No module named 'imblearn'
I have tried installing the imblearn module in multiple ways, they all seem to work (there are no errors given during the installation but when I run the above code, I get an error message).
I tried istalling imblearn using the following suggested in other stackoverflow questions:
pip install -U imbalanced-learn
pip install imblearn
!pip install imblearn
pip install -c glemaitre imbalanced-learn
pip install imblearn==0.0
None of these seem to help... Any ideas? Thank you!
I installed the module named imblearn using anaconda command prompt.
conda install -c conda-forge imbalanced-learn
Then imported the packages
from imblearn import under_sampling, over_sampling
from imblearn.over_sampling import SMOTE
Again, I tried to install imblearn through pip, it works for me.
(base) C:\WINDOWS\system32>pip install -U imbalanced-learn
Requirement already up-to-date: imbalanced-learn in c:\users\ashok\anaconda3\lib\site-packages (0.4.3)
Requirement already satisfied, skipping upgrade: numpy>=1.8.2 in c:\users\ashok\anaconda3\lib\site-packages (from imbalanced-learn) (1.15.3)
Requirement already satisfied, skipping upgrade: scipy>=0.13.3 in c:\users\ashok\anaconda3\lib\site-packages (from imbalanced-learn) (0.19.1)
Requirement already satisfied, skipping upgrade: scikit-learn>=0.20 in c:\users\ashok\anaconda3\lib\site-packages (from imbalanced-learn) (0.20.0)
On AWS SageMaker, follow the documentation:
!pip install imbalanced-learn
in a notebook cell.
This worked for me
First install the package in your environment:
pip install -U imbalanced-learn
Next:
conda install -c conda-forge imbalanced-learn
Open anaconda prompt and install below module:
conda install -c conda-forge imbalanced-learn
conda install -c conda-forge/label/gcc7 imbalanced-learn
conda install -c conda-forge/label/cf201901 imbalanced-learn
Those who have permission issue or failed to install it can follow this.
conda create --name dsc_new
conda activate dsc_new
conda install -c conda-forge imbalanced-learn
try on your notebook pip install imbalanced-learn --user
I have been fixed it by applying the following inside a Jupyter Notebook.
!pip install imbalanced-learn==0.6.0
!pip install scikit-learn==0.22.1
I had the same issue which was rectified by using:
!pip install -U imbalanced-learn
Then this:
conda install -c conda-forge imbalanced-learn
Updated my conda:
conda update -n base -c conda-forge conda
Restarted the kernel.
try this way:
from imblearn import under_sampling
from imblearn import over_sampling
from imblearn.over_sampling import SMOTE
OR
import imblearn *
I've come across the same problem a few days ago - trying to use imblearn inside a Jupyter Notebook. This question led me to the solution:
conda install -c glemaitre imbalanced-learn
Notice, one of the commands you tried (pip install -c glemaitre imbalanced-learn) doesn't make sense: -c glemaitre is an argument for Anaconda python distributions, which tells conda (Anaconda's CLI) to download the module from a source different than the defaults (glemaitre's channel). Since that argument is conda-specific, it doen't apply to pip commands.
Using python=3.6.10 and below worked for me.
I was dealing with the same problem. Updating packages, upgrading pip or python version did not resolve the problem for me.
The issue was that pip installed package to one folder, but my jupyter notebook imported packages from another folder. To get the path from where your packages are imported, you may use:
import site
site.getsitepackages()
# /your/path/from/python
Then you may check in terminal where pip installs your packages :
pip show imblearn
If the paths do not coincide, you may manually set the path for pip in terminal:
pip config set global.target /your/path/from/python
And install your package again by
pip install imblearn
If you are still experiencing error after installing imblearn either on Anaconda terminal while using Vscode. Try to restart Vscode for it to reflect.

how conda instal pip (Theano) on ubuntu?

I try to install theano use conda install pip theano but always failed.
and I try to install using sudo, but when I try to import no module named theano.
you either use:
conda install theano
or
pip install theano
conda and pip are two distinct installers that you need to have on your machine first; pip comes with python; conda is a separate tool, usually installed with an anaconda distribution
To check if you have conda installed, type which conda in your terminal.
to update conda, type conda update conda

Categories