Problems with Fortran-magic and other jupyter lab extensions - jupyter-lab

I am originally a Fortran programmer, if anything. Last year I begun learning python and now I wanted to use fortranmagic to have a wrapper of f2py, but it is not working. Let me describe the steps I took and the resulting error messages, hoping for some help. I am working with Ubuntu 22.04
I begun by creating an environment conda create -n lf and activating the environment
I installed I few libraries I might need
conda install numpy scipy matplotlib jupyter nodejs
Following the instructions of the Fortran-magic developer GitHub I run pip install -U fortran-magic
Everything installs fine, but when I create a notebook and execute
%load_ext fortranmagic
I get the following error ModuleNotFoundError: No module named 'fortranmagic'
4. I finally try to install the extensions from jupyter, as it is also suggested in the developer GitHub
%install_ext https://raw.github.com/mgaitan/fortran_magic/master/fortranmagic.py
Yet only to receive the following error UsageError: Line magic function %install_ext not found.
I hope you can help

Related

ImportError cannot import 'langauge' from 'google.cloud' (unknown location)

I'm trying to incorporate google-cloud-language to use sentiment analysis. I followed the guide on the google documentation website, like so:
from google.cloud import language
When I run the script I receive the following error:
ImportError cannot import 'langauge' from 'google.cloud' (unknown location)
I try to run the script like so:
python3 scriptName.py
I've installed google-cloud-language like so:
pip3 install gooogle-cloud-language
pip install google-cloud-language
I've done that in a virtual environment and outside a virtual environment.
Nothing works. How do I properly set up my script to successfully import the NLP module from google cloud?
Happy to see that you resolved your issue. However, I would like to point some things out:
In the error that you posted in the description there is a typo. It looked for a module named langauge instead of language.
pip3 install gooogle-cloud-language and python3 -m pip install google-cloud-language should be equivalent but that may not always be the case. For example when they are not in the same path. Check this answer for more details.
As I was writing this question and going through other similar questions on stackoverflow, I found another command to try and it seems to have worked.
python3 -m pip install google-cloud-language
I did this inside my virtualenv. It could also work outside of one, but because I got it working, I did not test the outside virtualenv case.

ModuleNotFoundError when accessing python Flask within jupyter notebook in a virtual env

I have created an virtual env gcloudenv on my nividia nano running ubuntu. I was able to successfully install flask and required libraries and able to deploy my appengine into GCP from this virtual env. All my work is in python and I was using nano as my editor to get my code up and running. No issues so far.
my virtual env gcloudenv already has all the required packages for flask, jinga etc and I can see them when I run pip freeze.
Then I tried to work on Jupyter notebook as my code was getting little complicated and I didn't want to write full code and then run.
I already had jupyter notebook installed before creating the virtual env. I also installed jupyter within in virtual env as well.
So I followed the instruction to create a new kernel by running the following command:-
(gcloudenv) sunny#my-nano:~gcloudenv/MyApp/mainfolder$ pip install ipykernel
(gcloudenv) sunny#my-nano:~gcloudenv/MyApp/mainfolder$ ipython kernel install --user --
name=gcloudenv
Now, I ran the notebook as:
(gcloudenv) sunny#my-nano:~gcloudenv/MyApp/mainfolder$
/home/gcloudenv/bin/jupyter notebook
When trying to import the flask I get the following error:
ModuleNotFoundError: No module named 'flask'
Note sure what is going on as I getting blanked out.
Add
!pip install flask
in the beginning of your Jupyter notebook.
Finally I managed to solve my problem. Thanks to a wonderful post https://jakevdp.github.io/blog/2017/12/05/installing-python-packages-from-jupyter/.
In essence, I had 2 problems:-
1. I did not have a jupyter-notebook within my virtual env. Originally I thought I had it installed but that was incorrect. so whenever I tried to launch one, it was picking the first jupyter notebook it could find in the path.
The good way to find out which one is it pointing to , is to run which command
(gcloudenv) sunny#my-nano:~/gcloudenv$ which jupyter-notebook
For me, that was at:
/home/sunny/archiconda3/bin/jupyter-notebook
I had in fact 3 copies of jupyter-notebook on my system. One was probably installed using sudo pip and therefore went into the root folder. Probably not a good thing to do.
So I installed a fresh jupyter-notebook with the following command:-
(gcloudenv) $ pip install jupyter notebook
2.Next is to check list of Jupyter kernels available by running the following from the jupyter notebook ( or from command line):
!jupyter kernelspec list (OR (gcloudenv) $jupyter kernelspec list
My jupyter notebook was not able to import flask libraries because it was pointing to a wrong kernel config outside of my virtualenv gcloudenv.
Available kernels:
gcloudenv /home/sunny/.local/share/jupyter/kernels/gcloudenv ( correct one)
python3 /home/sunny/gcloudenv/share/jupyter/kernels/python3
You can determine which python version it is picking by doing a 'more' on the file:-
(gcloudenv) $
/more/home/sunny/.local/share/jupyter/kernels/gcloudenv/kernel.json
Once I changed my kernel to point to python3 from within the notebook, it picked the correct path and all the relevant libraries I needed.
In summary when you hit the problem as mentioned above, do the following:-
check the path of the python ( whereis python or which python)
check if you are running the 'right' notebook. This is determined by the path and if you have sourced your virtualenv.
Install jupyter notebook using pip from within your virtualenv( do not use sudo)
Check the Jupyter kernel. This may be particularly relevant if you have a common jupyter notebook and you want to work with multiple virtualenv.

Pycharm, opencv fails to load dll, works on prompt

After installing miniconda with python 3.7 I do the following:
conda create --name opencv_test python=3.7
conda activate opencv_test
conda install -c anaconda opencv
Then to test the environement I do:
python
>>> import cv2
>>> exit()
Everything goes according to plan
Then if I launch PyCharm or vs code, set my new environment as the interpreter and create a simple file that contains only
import cv2
On launch I get:
ImportError: DLL load failed: The specified module could not be found.
What I learned from the internets:
This, this and this, all those posts refer to a problem that seems similar, the difference being that the issue for me only happens when using IDEs
What I tried before posting here:
Recreating the environment multiple times switching channels.
As it seemed to be a path issue, I added the paths which contained opencv dll to the environment paths in PyCharm settings one at a time
What I just tried after spending a considerable amount of time creating this post:
conda update conda
This weirdly downgrades python to 3.6
conda create --name opencv_test_2 python=3.6
conda activate opencv_test_2
conda install -c anaconda opencv
This seems to fix all the issues but:
I don't know what just happened and why the issue only appeared on IDEs
I'd like to use python 3.7
So in short, why when using python 3.7 and PyCharm I seem to be unable to import opencv even if it works on command line?
Thanks in advance.

IPython Notebook showing `ImportError`

I am using Ubuntu 15.04 and I just installed IPython 4.0.
Now, when I type ipython notebook in the terminal, I get the following error message:
ImportError: No module named notebook.notebookapp
I have read related questions on this site but I could not solve this situation.
Since, I have no working knowledge of IPython,so I could really use some advice to fix this.
Try pip install "ipython[notebook]"
and take a look here:
http://ipython.org/install.html#i-already-have-python.
This should install all the dependencies and get you up and running.

Anaconda3 libhdf5.so.9: cannot open shared object file [works fine on py2.7 but not on py3.4]

I just tried to use pd.HDFStore in IPython Notebook with a Python 3 kernel (Anaconda 2&3 on Ubuntu 14.04)
import pandas as pd
store = pd.HDFStore('/home/Jian/Downloads/test.h5')
but it throws the following error
ImportError: HDFStore requires PyTables, "libhdf5.so.9: cannot open shared object file: No such file or directory" problem importing
I initially thought it's because pytables is somehow missing, but when I check $source activate py34 and $conda list, pytables 3.2.0 is already installed under anaconda python3 environment.
Also, if I switch to Python 2, for example, $source activate py27 and start ipython notebook, it works properly and no import error is thrown.
I guess that I must miss something for configuring pytables under anaconda python 3 env, but I cannot figure it out. Any help is highly appreciated.
Update:
I just tried on a fresh install of Anaconda3-2.3.0-Linux-x86_64 from official website and it ends up with the same error. When I try $locate libhdf5.so.9 in command line, nothing shows up.
This is a known issue that we are working on. When it is fixed, conda update --all will update the libraries and fix the issue.

Resources