I am integrating gstreamer and pocketsphinx on mac using python 3.6; however, the first line of code, from gi import pygtkcompat, raises an error.
The command:
python3 demoapp_chinese.py
returns
Traceback (most recent call last):
File "demoapp_chinese.py", line 1, in
from gi import pygtkcompat
ModuleNotFoundError: No module named 'gi'
Here's how I install pygobject:
brew install pygobject3
And when I try to get more info. I execute
brew info pygobject3
which returns
pygobject3: stable 3.30.4 (bottled)
GNOME Python bindings (based on GObject Introspection)
https://wiki.gnome.org/Projects/PyGObject
/usr/local/Cellar/pygobject3/3.30.4 (69 files, 1.6MB) *
Poured from bottle on 2019-02-04 at 17:21:21
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/pygobject3.rb
(here I only post the first few couple of lines)
For the python info,
which python3
returns
/usr/local/bin/python3
Besides,
echo $PYTHONPATH
returns
/usr/local/lib/python3.6/site-packages
echo $PATH
returns
/Users/cindy/bin:/usr/local/bin/python3.6:/usr/local/lib/python3.6/site-packages:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public
Lastly, I don't know if this is normal, when I run
which pygobject3
NOTHING returns on the terminal.
Please help, thanks. If you need any extra info. to help me, please let me know.
Related
I realize this question might come off as an easy fix, but it has been annoying me for the last hour. I'm new to working in a Python environment on my Mac, and I can't seem to install the tweepy module in the directory that I'm working in.
First I installed Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Next I installed Python:
brew install python
Which resulted in:
Python has been installed as /usr/local/bin/python3
Then I attempted to install the Tweepy package within the path /Desktop/twitterBot:
pip3 install tweepy --user
Which resulted in:
Successfully installed tweepy-3.9.0
After this I wanted to check that the Tweepy package was successfully installed, so within my bot.py file, the only line I wrote was import tweepy
When attempted to run my code python bot.py within the path Desktop/twitterBot, I receive the error:
Traceback (most recent call last):
File "bot.py", line 1, in <module>
import tweepy
ImportError: No module named tweepy
I really appreciate your guys' help. Thanks.
As explained, you're running your code with a different version of Python than the one you installed Tweepy for.
Mac OS X 10.8 comes with Python 2.7 pre-installed by Apple.
Remember that if you choose to install a newer Python version from python.org, you will have two different but functional Python installations on your computer, so it will be important that your paths and usages are consistent with what you want to do.
https://docs.python.org/3/using/mac.html
Since you installed Tweepy for Python 3 with pip3, you'll need to use python3 to run your code.
See https://docs.brew.sh/Homebrew-and-Python.
I have a centos7 machine with python-2.7.5 installed as a default python.
For my work, I need 3.x version of python on the same machine, so I have installed python-3.6.8 and created a soft link where /usr/bin/python point to /usr/bin/python3 with following command:
sudo ln -fs /usr/bin/python3 /usr/bin/python
Now, for a sample python script, let's say: test.py, I am getting ModuleNotFoundError: No module named 'yaml' error when I am trying to import yaml in it.
test.py script is as below:
#!/usr/bin/python3
"""
Sample python script to import yaml.
"""
import yaml
print("Hello! Could you please help me resolve this?")
And the error is as below:
[cloud-user#xx.xx.xx.xx]$python test.py
Traceback (most recent call last):
File "test.py", line 6, in <module>
import yaml
ModuleNotFoundError: No module named 'yaml'
I saw a couple of queries raised on stackoverflow and on github, like this, this and this, but do not see any response that has resolved this issue.
As suggested on the links above, I have installed pyyaml using below command:
sudo python3 -m pip install pyyaml and sudo pip3 install pyyaml but I am still continue to get ModuleNotFoundError error.
Could anyone please help me resolve this issue?
Thanks in advance,
Akshat Sharma
Such issues occur when there are multiple distribution of python installed in your system.
Just run: pip3 list command and see whether you are able to see the package in the list. If not, you are not installing the PyYaml package at the correct location.
PS: also sometimes for normal user python is at different location and for sudo user, it is at different location. Check running the command without giving sudo.
I have an issue with Python on my Mac with High Sierra.
After running pip install pysal, I have a successful installation. However, the module is not found when I run in python:
> import pysal
Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named pysal
I do not face such errors when running the same command in python2. However, most of my python scripts call the interpreter at the beginning of the file with #!/usr/bin/env python, so I would prefer not having to rely on python2 (I don't know how to do it either).
I figured out that this is python's executable is not on the same location where pip installs the modules:
macbook-pro-3:~ ME$ which -a python
/usr/bin/python
macbook-pro-3:~ ME$ which -a pip
/usr/local/bin/pip
I tried to follow the solution proposed by #J0ANMM in Modules are installed using pip on OSX but not found when importing . It recommeds downloading the script get-pip.py and executing it with sudo /usr/bin/python get-pip.py. I tried, but it did not change anything (the previous which commands still yield the same thing).
How do I manage to make pip work with my version of python?
I use this tutorial text as an example, there are others:
#!/usr/bin/python
import MySQLdb
If it produces the following result, then it means MySQLdb module is not installed −
Traceback (most recent call last):
File "test.py", line 3, in <module>
import MySQLdb
ImportError: No module named MySQLdb
To install MySQLdb module, use the following command −
For Ubuntu, use the following command -
$ sudo apt-get install python-pip python-dev libmysqlclient-dev
I have gone trough these steps, more or less as described above.
Problem is that the subdirectory "python" does not exist under /usr/bin/
in my file system. I run Linux Mint 18.3. Python 2.7 seems to be the native version installed in Mint (used for several purposes), but I have also installed Python 3.6.4 and wish to use this for development purposes.
Does anyone know in which directory I could expect to find MySQLdb?
Since #!/usr/bin/python is non existent I wonder - has MySQLdb been properly installed? If it has, I have not after several efforts succeded in locating it.
Here is a post about installing a module in python3. When I use brew install python, then it installs it for 2.7.
When I use the method suggested by dan, which aimed to install it directly in python3 (who i really thank), but which didn't work :
# Figure out the path to python3
PY3DIR=`dirname $(which python3)`
# And /then/ install with brew. That will have it use python3 to get its path
PATH=$PY3DIR:$PATH brew install mapnik
The installation was successful but in python2. so I get:
For non-homebrew Python, you need to amend your PYTHONPATH like so: export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH
so i finally add the path manually in python3 :
import sys
sys.path.append('/usr/local/lib/python2.7/site-packages')
I get this error :
Traceback (most recent call last): File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/mapnik/__init__.py", line 69, in <module>
from _mapnik import * ImportError: dlopen(./_mapnik.so, 2): Symbol not found: _PyClass_Type Referenced from: ./_mapnik.so
Expected in: flat namespace in ./_mapnik.so
Please help, I have spent so many hours on this ...
Thanks!!!
The Mapnik python bindings depend on boost_python. And both need to use the same python. The problem is likely that homebrew is providing a bottle of boost which includes boost python built against python 2.7 and not python 3.x.