ModuleNotFoundError: No module named 'fasttext' - python

I have tried installing fasttext through conda using two channels:
conda install -c conda-forge fasttext
and
conda install -c conda-forge/label/cf201901 fasttext
as per (https://anaconda.org/conda-forge/fasttext).
I am using the following command to import: import fasttext
However, the import fails with the error:
ModuleNotFoundError Traceback (most recent call
last) in
----> 1 import fasttext
ModuleNotFoundError: No module named 'fasttext'
However, tried to import it in an older fashion import fastText, which failed.
Have tried it on python and python3, both of which fail.
I want to avoid installing it using pip and manage the packages using conda.
conda list shows that fasttext being installed. The output of which is shown below:
fasttext 0.2.0 hfc679d8_1 conda-forge/label/cf201901
The output of python -c 'import sys; print(sys.path) is as below:
['', '/<dir>/<dir>/anaconda3/lib/python37.zip', '/<dir>/<dir>/anaconda3/lib/python3.7', '/<dir>/<dir>/anaconda3/lib/python3.7/lib-dynload', '/<dir>/<dir>/anaconda3/lib/python3.7/site-packages']

I used fastText in this way:
!git clone https://github.com/facebookresearch/fastText.git
!cd fastText
!pip install fastText
import fasttext.util
fasttext.util.download_model('en', if_exists='ignore') # English
model = fasttext.load_model('cc.en.300.bin')
Note 1: Pay attention to uppercase letters.
Note 2: Here is the list of supported languages.

Related

How to properly install MEEP in Google Colab?

In the past I have installed the pymeep package in Google Colab with the following cell:
!wget -c https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
!chmod +x Miniconda3-latest-Linux-x86_64.sh
!bash ./Miniconda3-latest-Linux-x86_64.sh -b -p ./anaconda
import os
os.environ['PATH'] += ":/content/anaconda/bin"
!conda create -n mp -c conda-forge pymeep
import sys
sys.path.append('/content/anaconda/envs/mp/lib/python3.7/site-packages/')
Which is an exact copy from this website: https://rf5.github.io/2019/12/22/meep-intro.html
Sometimes the code I wrote doesn't work. It executes without errors, but when I try to execute import meep as mp. I get the following error:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-2-f30f3b609667> in <module>()
----> 1 import meep
ModuleNotFoundError: No module named 'meep'
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------
Is there a better way of installing meep or rather pymeep in Google Colab?
Replace 3.7 with 3.8 as the latest python version installed using conda is 3.8
sys.path.append('/content/anaconda/envs/mp/lib/python3.8/site-packages/')
Example

How to know torch version that installed locally in your device

I want to check torch version in my device using Jupyter Notebook.
I'm used this
import torch
print(torch.__version__)
but it didn't work and Jupyter notebook raised an error as below
AttributeError Traceback (most recent call last)
<ipython-input-8-beb55f24d5ec> in <module>
1 import torch
----> 2 print(torch.__version__)
AttributeError: module 'torch' has no attribute '__version__'
Is there any command to check torch version using Jupyter notebook?
Try this. Open your terminal
python3 -c "import torch; print(torch.__version__)"
I have tried to install new Pytorch version. But, it didn't work and then I deleted the Pytorch files manually suggested on my command line. Finally, I installed new Pytorch version using conda install pytorch torchvision torchaudio cudatoolkit=11.0 -c pytorch and everything works fine.
This code works well after that.
import torch
print(torch.__version__)
You can check list all installed python modules with version tag via pip.
To ensure running the proper pip version, just execute it via the python interpreter:
# python symlink
python -m pip freeze
# python3
python3 -m pip freeze
You can grep for the module of question (used numpy as an example)
python -m pip freeze | grep numpy
numpy==1.19.4
If in the terminal, use pip.
user#debian:~/..$ pip3 show torch
Name: torch
Version: 1.11.0
Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration
Home-page: https://pytorch.org/
Author: PyTorch Team
Author-email: packages#pytorch.org
License: BSD-3
Location: /home/user/.local/lib/python3.7/site-packages
Requires: typing-extensions
Required-by: torchaudio, torchvision

ModuleNotFoundError: No module named 'pymc3'

I'm trying to import PyMC3 library in Jupyter Notebook's Python 3 kernel. I've already installed pymc3 initials in Anaconda Prompt (Miniconda3) using:
conda install theano
conda install pygpu
pip install pymc3
And when I try to import it in Jupyter Notebook:
import pymc3 as pm
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-1f817cf6472a> in <module>
1 # PyMC3 for Bayesian Inference
----> 2 import pymc3 as pm
ModuleNotFoundError: No module named 'pymc3'
Any solutions to this problem guys...
You have installed the pymc3 to other python environment that you are using to import it.
Check your python executable location
Inside your script, use
import sys
print(sys.executable)
To get the path to the python executable you are using. Lets say it is C:\python\python.exe.
Install the package
Then, install the package using
<path_to_python.exe> -m pip install pymc3
This is the bulletproof way installing packages with pip, when you have multiple python installations or virtual environments on your system.

xgboost on Sagemaker notebook import fails

I am trying to use XGBoost on Sagemaker notebook.
I am using conda_python3 kernel, and the following packages are installed:
py-xgboost-mutex
libxgboost
py-xgboost
py-xgboost-gpu
But once I am trying to import xgboost it fails on import:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-5-5943d1bfe3f1> in <module>()
----> 1 import xgboost as xgb
ModuleNotFoundError: No module named 'xgboost'
In Sagemaker notebooks use the below steps
a) If in Notebook
i) !type python3
ii) Say the above is /home/ec2-user/anaconda3/envs/python3/bin/python3 for you
iii) !/home/ec2-user/anaconda3/envs/python3/bin/python3 -m pip install xgboost
iv) import xgboost
b) If using Terminal
i) conda activate conda_python3
ii) pip install xgboost
Disclaimer : sometimes the installation would fail with gcc version ,in that case update pip version before running install

Can not get pytorch working with tensorboard

I"m going through this tutorial to set up pytorch (v1.3.0 through conda) with tensorboard https://pytorch.org/tutorials/intermediate/tensorboard_tutorial.html#
but on the step
from torch.utils.tensorboard import SummaryWriter
# default `log_dir` is "runs" - we'll be more specific here
writer = SummaryWriter('runs/fashion_mnist_experiment_1')
I keep getting the error
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
C:\ProgramData\Anaconda3\envs\fastai_v1\lib\site-packages\torch\utils\tensorboard\__init__.py in
1 try:
----> 2 from tensorboard.summary.writer.record_writer import RecordWriter # noqa F401
3 except ImportError:
ModuleNotFoundError: No module named 'tensorboard.summary'; 'tensorboard' is not a package
During handling of the above exception, another exception occurred:
ImportError Traceback (most recent call last)
c:\Users\matt\Documents\code\playground\tensorboard.py in
----> 1 from torch.utils.tensorboard import SummaryWriter
2
3 # default `log_dir` is "runs" - we'll be more specific here
4 writer = SummaryWriter('runs/fashion_mnist_experiment_1')
C:\ProgramData\Anaconda3\envs\fastai_v1\lib\site-packages\torch\utils\tensorboard\__init__.py in
2 from tensorboard.summary.writer.record_writer import RecordWriter # noqa F401
3 except ImportError:
----> 4 raise ImportError('TensorBoard logging requires TensorBoard with Python summary writer installed. '
5 'This should be available in 1.14 or above.')
6 from .writer import FileWriter, SummaryWriter # noqa F401
ImportError: TensorBoard logging requires TensorBoard with Python summary writer installed. This should be available in 1.14 or above.
Does anyone have any suggestions?
The error log says, among other things,
ImportError: TensorBoard logging requires TensorBoard with Python summary writer installed. This should be available in 1.14 or above.
So, when it tries to import TensorBoard, it's unable to do so because it's missing it in the search path. You can install the latest version (without specifying any version number), as in:
$ conda install -c conda-forge tensorboard
Apart from that, you might also need to install protobuf:
$ conda install -c conda-forge protobuf
These installations should fix the ImportErrors.
I came across the same error, I solved by taking the following steps:
Removed all installation of Tensorflow or Tensorboard from the conda environment.
Then by activating the same conda environment, type "pip install -U tb-nightly"
Then type, "pip install -U future"
done
I think it's a version problem.
just run this:
pip install tensorboard==1.14.0
(not pip install tensorboard==1.14)
or just install the tensoflow 1.14.0, which contains the tensorboard 1.14.0:
pip install tensorflow==1.14.0
This version of tensorflow worked for me in pytorch 1.2.
I've done:
conda install -y tensorboard
before with no problems, so Im not sure why that wouldn't work. It's the simplest.
I met the same error, and my conda also didn't work that time, so I chose to use tensorboardX, it is almost absolutely the same as tensorboard(also its operations).
Just install it with pip install tensorboardX
And you can import it with from tensorboardX import SummaryWriter

Categories