I'm very new to python and protocol buffer. We've come across a scenario where we have to push metrics to mimir (prometheus). I downloaded and compiled proto definition (https://github.com/grafana/mimir/blob/main/pkg/mimirpb/mimir.proto). There is a line in it:
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
Once the proto is compiled and mimir_pb2 package generated, importing it throws ModuleNotFound Error:
python3
>>> import mimir_pb2
>>> ModuleNotFoundError: from github.com.gogo.protobuf.gogoproto import gogo_pb2 as github_dot_com_dot_gogo_dot_protobuf_dot_gogoproto_dot_gogo__pb2
ModuleNotFoundError, Module github not found.
Compiling mimir.protoc has generated this line in mimir_pb2:
from github.com.gogo.protobuf.gogoproto import gogo_pb2 as github_dot_com_dot_gogo_dot_protobuf_dot_gogoproto_dot_gogo__pb2
Has anyone come across this error before? I'm not sure what/where github.com.gogo.protobuf.gogoproto is/has to be, and how I can resolve the issue.
I found the problem. I also had to download gogo.proto file and compile it. This created gogo_pb2 where I referenced it in the original class.
Python protobuf gRPC generates a dependency that doesn't exist
Related
I'm trying to make a simple import and use the emailage third party library.
As per their documentation, the way to use their library is as follows:
pip install emailage-official
Then, simply import with:
from emailage.client import EmailageClient
The install works fine with pip - no errors. I double checked to see that the emailage package exists within the proper directory, and it does.
Package exists at:
C:\Users\aaron\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\emailage
This folder has (seemingly) the correct files with an __init__.py and everything. However, both pylint and command line interpreter throw me a
'No module named 'emailage.client'; 'emailage' is not a package' error.
The output of my sys.path is:
[...
'C:\\Users\\aaron\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages'
...
]
So the directory where emailage is installed is a part of the path... and lastly I pip-installed numpy just to test if it worked properly. Numpy installed to the same site-packages folder as emailage, and it works fine when it is imported, so I'm stuck.
I don't typically use Python much, so any and all help would be appreciated.
The issue was in the naming of my file.
I hastily named my file emailage.py and then tried to import from emailage.client.
I'm assuming that Python looked in my current directory and matched the names of the file I was working on before checking the installed third party libraries.
After renaming my file everything seems ok.
For others who run into similar problems -- beware of conflicting naming. Sometimes the simplest things trip you up the longest.
I ran into something similar and the answer from OP about namespace collision is what finally clued me in.
I was using the same name for both a sub-package (directory) and a module (file) within it.
For example I had this:
/opt/mylib/myapi
/opt/mylib/myapi/__init__.py
/opt/mylib/myapi/myapi_creds.py # gitignored file for user/pass
/opt/mylib/myapi/myapi.py # base module, load creds and connect
/opt/mylib/myapi/myapi_dostuff.py # call myapi.py and do work
The script 'myapi.py' imports credentials from myapi_creds.py via this statement:
from myapi.myapi_creds import my_user, my_pass
Testing the module 'myapi.py' resulted in this error:
$ ./myapi.py
Traceback (most recent call last):
File "./myapi.py", line 12, in <module>
from myapi.myapi_creds import my_user, my_pass
File "/opt/mylib/myapi/myapi.py", line 12, in <module>
from myapi.myapi_creds import my_user, my_pass
ModuleNotFoundError: No module named 'myapi.myapi_creds'; 'myapi' is not a package
The solution was to rename myapi.py to myapi_base.py so it's name does not collide with the sub-package name.
I took a look at this problem, and even though it is not exactly the same error that I encountered, it helped me solve it. I'll explain the situation I had, since I think some users might find this handy.
So, I was getting the following error log:
Traceback (most recent call last):
File "/home/kemal/Programming/Python/Preference_Articulation/LocalSearch/LS_apriori.py", line 1, in <module>
from LocalSearch.LocalSearch import LocalSearch
ModuleNotFoundError: No module named 'LocalSearch.LocalSearch'; 'LocalSearch' is not a package
The structure of my project is the following (using PyCharm):
View of project structure
The important thing to notice is that I separated my code into several folders, since it makes it more readable. Now, in the folder named LocalSearch I have 4 files, LocalSearch, LS_apriori and some 2 tests files (not relevant). When trying to run the file LS_apriori (which uses methods and classes from file LocalSearch) I was getting the error provided above. The code specifically is not important, and the way I handled the imports was the following:
from LocalSearch.LocalSearch import LocalSearch
The fix was simple. I renamed the py-file LocalSearch to Local_Search (just added an underscore). Afterwards, the error was gone.
So my problem was possessing a folder(package) with the same name as a file(module) inside it, which has a class inside it with the same name. Python didn't like that.
Having modules with the same name as packages inside them is fine however, I guess the class just added extra confusion.
My goal is to acquire image from an Allied Vision camera thanks to Python (Anaconda 3.7). For that I tried to use the "Pymba" package but I get the error : “AttributeError: module has no attribute”.
I looked in the previous posts but I didn't find any working solution. I put below some of my tests.
Here is my code :
import pymba
with pymba.Vimba() as vimba:
print (vimba.getVersion())
system = vimba.getSystem()
The precise error :
File "<ipython-input-2-ff80570a1f3d>", line 3, in <module>
print (vimba.getVersion())
AttributeError: 'Vimba' object has no attribute 'getVersion'
And here are some informations that could be usefull about my research to solve this problem:
I checked if the package was correctly installed.
from pymba import Vimba, PYMBA_VERSION
print(PYMBA_VERSION)
print(Vimba.version())
0.3.2
1.7.0
Despite the fact that I don't have any other file named "Pymba", I checked what file was imported:
print(pymba.__file__)
C:\Users\agricultu\Anaconda3\lib\site-packages\pymba\__init__.py
I don't have either a previous file named "getVersion" and I get the same error for every other function of the package anyway.
I'm running out of ideas and I hope one of you will be able to help me.
I recently downloaded a package and when testing the package to see if everything works correctly I get the error ImportError: No module named 'cubicspline'. When following the trail to see where is error occurs I found that cubicspline.py (the file not being found) is in the same folder as extcurve_s16.py (the file calling cubicspline).
File "/Users/Austin/anaconda/lib/python3.5/site-packages/isochrones/schlafly/extcurve_s16.py", line 4, in <module>
import cubicspline
I've checked the permissions on the folder and I'm able to both read and write. There is also an __init__.py file in the folder. Any ideas here? I can't figure out why it wouldn't be able to call a file that is in the same folder. Here is the exact chunk of code for reference, as can be seen import numpy works fine.
import numpy
import cubicspline
The issue was resolved by cloning the isochrones package from Github instead of using pip install isochrones. There was some type of issue with the pip version.
I am trying to run this python rewrite of Vlfeat library.
https://github.com/shackenberg/phow_caltech101.py. I am trying to run the application phow_caltech101.
This is throwing
File "/A/B/C/pyvlfeat-0.1.1a3/vlfeat/__init__.py", line 1, in <module>
import _vlfeat
ImportError: No module named _vlfeat
In the corresponding "init.py" file, I can see it is mentioned as "import _vlfeat". I am new to python, please let me know what is causing this error?
You need to download and install PyVlfeat module.
https://pypi.python.org/pypi/pyvlfeat/
As I see, pyvlfeat has some dependencies, so be sure to download these too:
Boost.Python (tested against version 1.35.0-5)
NumPy (tested against version 1.5.1)
Matplotlib (tested against version 0.99.3)
Im trying to compile Godot engine following the instructions here
When I run scons bin/godot as the tutorial says, I get the following error:
scons: Reading SConscript files ...
ImportError: cannot import name _args_from_interpreter_flags:
File "/home/grayfox/github/godot2/godot/SConstruct", line 9:
import multiprocessing
File "/usr/lib64/python2.7/multiprocessing/__init__.py", line 65:
from multiprocessing.util import SUBDEBUG, SUBWARNING
File "/usr/lib64/python2.7/multiprocessing/util.py", line 40:
from subprocess import _args_from_interpreter_flags
The SConstruct file starts this way:
EnsureSConsVersion(0,14);
import string
import os
import os.path
import glob
import sys
import methods
import multiprocessing
...
If I try to run python SConstruct I get an error complaining about missing functions defined by scons (i.e. the script fails after doing all the imports).
Commenting import multiprocessing fixes the issue but I don't want to modify that file, as I would have to revert the change if I ever make a pull request. The project is quite active so I believe this has something to do with my local configuration.
Any ideas why the script is failing to import _args_from_interpreter_flags only if I execute it via scons?
[UPDATE]
I did a fresh Gentoo install and the problem persists. I did some tests and I found this:
In a python terminal>
>>> import SCons.Script
>>> from subprocess import _args_from_interpreter_flags
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name _args_from_interpreter_flags
>>> import subprocess
>>> subprocess.__file__
'/usr/lib64/python2.7/site-packages/SCons/compat/_scons_subprocess.pyc'
But the output is different if I do this:
>>> import subprocess
>>> subprocess.__file__
'/usr/lib64/python2.7/subprocess.pyc'
So I update my question: Is this a bug? Can anybody reproduce it in other distros? If it's a bug, should I report it to Gentoo or to SCons?
[ANOTHER UPDATE]
Adding temp.extend([os.path.join(x, 'lib64') for x in prefs]) did't work, same error.
Adding print sys.path at the beginning of the compact module gives:
['/usr/lib64/python-exec/python2.7/scons-local-2.3.0',
'/usr/lib64/python-exec/python2.7/scons-local',
'/usr/lib64/python2.7/site-packages/lib32/scons-2.3.0',
'/usr/lib32/scons-2.3.0',
'/usr/local/lib32/scons-2.3.0',
'/usr/lib64/python2.7/site-packages/lib/python2.7/site-packages/scons-2.3.0',
'/usr/lib/python2.7/site-packages/scons-2.3.0',
'/usr/local/lib/python2.7/site-packages/scons-2.3.0',
'/usr/lib64/scons-2.3.0',
'/usr/lib64/python2.7/site-packages/lib32/scons',
'/usr/lib32/scons',
'/usr/local/lib32/scons',
'/usr/lib64/python2.7/site-packages/lib/python2.7/site-packages/scons',
'/usr/lib/python2.7/site-packages/scons',
'/usr/local/lib/python2.7/site-packages/scons',
'/usr/lib64/scons',
'/usr/lib64/python2.7/site-packages/RBTools-0.6-py2.7.egg',
'/usr/lib64/python27.zip',
'/usr/lib64/python2.7', #It's here, so what's the problem?
'/usr/lib64/python2.7/plat-linux2',
'/usr/lib64/python2.7/lib-tk',
'/usr/lib64/python2.7/lib-old',
'/usr/lib64/python2.7/lib-dynload',
'/usr/lib64/python2.7/site-packages',
'/usr/lib64/python2.7/site-packages/gtk-2.0',
'/usr/lib64/python2.7/site-packages/wx-2.8-gtk2-unicode']
It looks as if this isn't really a problem connected to SCons directly. You might have an alien "subprocess" module/package installed in your system. Also check out Cannot import name _args_from_interpreter_flags which seems to be related.
Based on your updated question: I tried to compile Godot on my machine (Python 2.7.3, SCons 2.3.1, Ubuntu 12.04 LTS) and it's running fine, so the problem is not related to the provided SConstruct (and its supporting build description files in subfolders). The "_scons_subprocess" module gets used only when the import of the original "subprocess.py" fails. So I suspect that the SCons start script sets up a wrong sys.path, which may happen under 64bit (see issue http://scons.tigris.org/issues/show_bug.cgi?id=2657 ).
After you added "temp.extend([os.path.join(x, 'lib64') for x in prefs])", your "print sys.path" statement shows paths like "/usr/lib64/python-exec" in its output. A Google search turned up the page http://forums.gentoo.org/viewtopic-t-985402-start-0.html for me. It describes an issue with Gentoo, where programs are installed as links to pip. Please follow the given advice and see if this fixes your problem.
It's a bug in Gentoo's scons-2.3.0 and scons-2.3.1 ebuilds (see bug report). It has been fixed in versions 2.3.1-r1 and higher.