I'm very new to Python and was trying to run a demo program. I'm getting the " no gi module found" error. I've been researching this and I've tried the remedies offered. The module is missing and repeated attempts to install have all failed. I've had a few surprises with other software since I've acquired a new MacBook running OSX Catalina and I'm wondering if there is a connection.
The answer is NO.
The reason I was getting the behavior I describes was that the gi module is not present in the installation of python that I was using, namely the factory installation on my new MacBook. I was aware that python 2 came installed on Macs. Using Homebrew, I installed python3 thinking I had to in order to get into python programming.
Using "which python" in Terminal, I found a python3 installation in /usr/bin/python3. I could find no 'gi' module in this installation and it is version 3.7.3. Using "which python3" I found a python3 alias in /usr/local/bin/python3. There is a 'gi' module with that one and it is version 3.7.7 with the original file python3.7 located in the Cellar of Homebrew.
I confirmed interactively that running this version DID NOT generate the error:
SMMac3:~-> python3
Python 3.7.7 (default, Mar 23 2020, 10:54:01)
[Clang 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import gi
>>> exit
So I added the following lines to the .zshrc file:
alias python=/usr/local/bin/python3
alias python3=/usr/local/bin/python3
And I no longer get the 'module not found' error. :)
Now I have a new problem which I will ask about in a separate question...
Related
When I try to use
import praw
I get the following error:
ModuleNotFoundError: No module named 'praw'
I made sure to install praw beforehand in the command prompt, using pip install praw, so I'm not sure why it isn't working. I'm new to programming, so any insight would be greatly appreciated.
It depends on the python version (yours say Python3.9) in your environment.
Try pip3 to install your packages.
I would open up the terminal and do the following:
$ pip3 install praw
$ python3 myscript.py
I had the same problem and was looking into several ways to solve it.
For me the solution was as simple as changing the name of the pyhton file to some like "test" instead of "praw".
Yes, I named my file "praw.py" and was importing praw which was the origin of the error.
You could very well be having an issue with multiple python installations across your system. I suggest cleaning up your environment, and using a virtual environment.
You should run the following to build a clean virtual environment in your working directory:
python -m venv venv
This will create a virtual environment which should be free of system-wide packages, and is a nice and shiny clean python installation.
Now you'll want to activate it. You said you were on Windows, so then run
venv\Scripts\activate.bat if you're using CMD, or venv\Scripts\Activate.ps1 if you're using PowerShell.
Now try reinstalling praw with python -m pip install praw. You should now always be able to access praw if you're in this virtual environment.
If you're interested on reading the documentation on VirtualEnvs, here it is. You might also be interested in checking out the Hitchhiker's Guide to Python, especially the chapter on virtual environments and package management. (Do note that this last chapter uses pipenv instead of virtualenv.)
I've installed praw using pip3 install praw. So it is not showing in my system default python i.e python 2.7.17.
cam#cam:~$ python
Python 2.7.17 (default, Sep 30 2020, 13:38:04)
[GCC 7.5.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import praw
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named praw
>>>
[5]+ Stopped python
cam#cam:~$ python3
Python 3.6.9 (default, Oct 8 2020, 12:12:24)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import praw
If you want to use praw with python2 you'll have to use:
pip install praw
If you want to use praw with python3 you'll have to use:
pip3 install praw
Thank you all so much for your help, but I have finally figured out what was causing my problem! In a separate file for the bot called requirements.txt, I had:
git+https://github.com/Rapptz/Discord.py
PyNaCl==1.3.0
pandas
dnspython==1.16.0
async-timeout==3.0.1
I simply added praw==7.2.0, and it worked! I appreciate your efforts in trying to help me :)
I install python 3.6.5_1 using
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/f2a764ef944b1080be64bd88dca9a1d80130c558/Formula/python.r
and get
Warning: python 3.6.5_1 is already installed
The currently linked version is 3.7.3
You can use brew switch python 3.6.5_1 to link this version.
I use brew switch python 3.6.5_1 and get
Cleaning /usr/local/Cellar/python/3.6.5_1
Cleaning /usr/local/Cellar/python/3.7.3
4 links created for /usr/local/Cellar/python/3.6.5_1
Typing which python3, there is no output, which python gives
/usr/local/bin/python
and typing python3 gives
-bash: /usr/local/bin/python3: No such file or directory
typing python gives
Python 2.7.15 (default, Nov 27 2018, 21:24:58)
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
How do I make sure that the installed python3.6.5_1 is installed at correct location and is the one referred to by python3?
Extra background :
I have been working with OpenCV for around 5 months now, following this installation guide for installing all requirements including python3.6. I was using this version of brew's python instead of mac's one. Recently I had to install FFmpeg, some errors came up, unwittingly I did something (I don't remember, probably unlinked python) and then I wasn't able to install FFmpeg anyway but also this destroyed my workspace. Right now I keep getting the following error everytime I open up terminal:
-bash: /usr/local/bin/python3: No such file or directory
virtualenvwrapper.sh: There was a problem running the initialization hooks.
If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3 and that PATH is
set properly.
I tried brew install python3 and that solves the above warning for virtualenvwrapper. But it installs python3.7.3, whereas I need python3.6 for tensor flow etc.
When I run python3 in terminal, it states that I am running Python 2.7.10. I updated a pip package and conda package and since I have no way of running python3. I am sure python 2 is running as writing 'print "hello"' works which is should not, if python3 successfully ran.
Daves-MBP:Desktop dave$ python3
Python 2.7.10 (default, Oct 6 2017, 22:29:07)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print "hello"
hello
This should NOT work if python3 is running.
How can I get python3 running when I want to?
Do I need to set up the environment path, or something else?
Good news. I have solved the problem myself (using a different forum article)
Setting the alias to the different python version in terminal solves this error.
$ alias python='python3.7'
$ alias python2='python2'
$ alias python3='python3.7'
So when I type 'python' in terminal, python3 is called. Not sure if my issue was an alias or path issue, as I was not aware of both concepts before I had the problem.
Make sure you have the python version installed before typing in python3.7 or 3.5 for instance.
Also, python3 alone does not work.
Type python3.1 or python3.3
Running into an issue I'm not sure how to resolve:
Installed VS Code, and used Homebrew to install Python 3.7, then installed Anaconda - was given an option to install it to my user home, and chose that option.
When I start up Terminal or VS Code though, I'm hitting this error - what have I likely missed?
Last login: Sat Dec 22 22:04:18 on ttys000
Traceback (most recent call last):
File "/Users/<myusername>/anaconda2/bin/conda", line 7, in <module>
from conda.cli import main
ImportError: No module named conda.cli
(Mac running Sierra)
I've attempted the following:
export PYTHONPATH="$HOME/.miniconda2/lib/python2.7:$HOME/.miniconda2/lib/python2.7/site-packages:$PYTHONPATH"
and the paths do appear to include Anaconda's paths. Python indicates Anaconda is present as well:
Python 3.7.1 (default, Dec 14 2018, 13:28:58)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
I'm sure I've missed a detail somewhere, but not sure what.
Likely this was a brute-force solution, but running anaconda-clean and then uninstalling anaconda2 and anaconda3, and finally reinstalling anaconda3 appears to have resolved this, since I don't actually need anaconda on Python2.7. I imagine the correct solution if I needed them both would be to set up additional environments to handle this.
I'm running an Anaconda virenv that has successfully installed OpenCV ver.3.4.1. From the python prompt I can import cv2 and can confirm it's version per the command line below:
Python 3.6.6 |Anaconda, Inc.| (default, Jun 28 2018, 11:07:29)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.4.1'
However, in VSCode I run the following simple program and get an error:
import numpy as numpy
import argparse
import cv2
pass
The error is:
Traceback (most recent call last):
File "detect_faces.py", line 3, in <module>
import cv2
ModuleNotFoundError: No module named 'cv2'
I don't understand why the command line import works, but the program from VSCode fails to import the same package.
There are multiple SO Q&A on this topic but they are all incredibly time/date sensitive and platform specific -- most deal with the situation where the package itself isn't recognized anywhere. The closest question is this one which is from 2015 and deals with the Android platform. Any thoughts?
Update
The version installed should be 3.5.5, but I noticed that in the command prompt launched from anaconda it's shown as Python 3.5.5 :: Anaconda, Inc. while the version shown within VSCode is Python 3.6.5 :: Anaconda, Inc.. When I look at the available env in VSCode it shows some 2.7s and several 3.6 versions - including the one I'm using which is 3.6.5.
I've just done a new install of a fresh Python 3.6 env and noticed that the command prompt reports Python 3.6.6 while the output from a sys check reports Python 3.6.5 -- again, both have the same executable path.
Although I was unable to replicate this same error, I did determine that it had to do with the installation of numpy. For whatever reason, it originally installed and downgraded the Python version within the venv. Then later when upgrading python it created a mismatch. The fix was to recreate the venv with a pip install of all three packages in the same command line. When installing all three at once the packages all reconcile - - I don't know if there was another variable - I couldn't recreate the original error.