I'm using bazel to manage a Python project, and there is currently an issue with the typing package:
File "<excluded>/pypi__typing/typing.py", line 1007, in __new__
self._abc_registry = extra._abc_registry
AttributeError: type object 'Callable' has no attribute '_abc_registry'
After some investigation on Google, this appears to have come from the old typing package that used to be installed via pip, and is now part of the Python standard library. This package no longer works, and so the recommended solution is to remove it and use the standard library one.
I can't do the recommended solution because I'm not using this package directly, and in a bazel environment I can't just run pip uninstall typing. I need to find out how the package is getting included, and remove it from the source.
How can I track down where the package is being imported?
Turns out you can just use bazel query to discover this.
Suppose your WORKSPACE file has this to import the dependencies:
pip_install(
name = "my_project_deps",
python_interpreter = "/usr/bin/python3",
requirements = "//my_project:requirements.txt",
)
You would then run the query:
bazel query 'allpaths(//my_project, #my_project_deps//pypi__typing)'
This gives me a result like this:
//my_project:target
//some/other:library
#my_project_deps//pypi__expiringdict:pypi__expiringdict
#my_project_deps//pypi__typing:pypi__typing
Seems like it's being pulled in by the expiringdict package.
How you actually remove the dependency is another question; if they don't have a newer version then you may have to fork the package and fix it yourself. In this case since typing is now part of the standard library, it is probably just a matter of removing it from that package's list of dependencies.
Related
I am creating a module, henceforth called mymodule, which I distribute using a pyproject.toml. This file contains a version number. I would like to write this version number in the logfile of mymodule. In mymodule I use the following snippet (in __init__.py) to obtain the version:
import importlib.metadata
__version__ = importlib.metadata.version(__package__)
del importlib.metadata
However this version is wrong. This appears to be the highest version which I have ever installed. For reference the command python3 -m pip show mypackage does actually show the correct version after installing the module locally. I struggle to explain this difference. Can anyone think of a cause of this discrepancy?
I also ran importlib.metadata.version(mypackage) which returned the same incorrect version.
The problem was related to left over build artifacts from using setup.py. importlib and pkg_resources will detect these artifacts in a local installation and pip will not. Deleting the mypackage.egg-info directory fixed the issue.
I'm working on a R package, that makes use of reticulate to call some functions of a Python package I implemented, installable through pip.
Following its documentation, I setup the reticulate automatic configuration of Python dependencies as follows, in the DESCRIPTION file of my package:
Config/reticulate:
list(
packages = list(
list(package="my_python_package", pip=TRUE)
)
)
where my_python_package is the Python package I need to use.
If I install the package locally, where I have the required Python package already installed, everything works fine.
However, if I try to install and use the R package in an environment without the Python package already installed, I get the following error:
Error in py_module_import(module, convert = convert) :
ModuleNotFoundError: No module named 'my_python_package'
Detailed traceback:
File "/home/runner/work/_temp/Library/reticulate/python/rpytools/loader.py", line 39, in _import_hook
module = _import(
as if reticulate is not able to configure correctly the environment.
Also, the Python package should not be the problem, since when it is installed, I am able to import it and use its functions with no errors.
From the reticulate documentation it seems Config/reticulate: ... is all is needed, but maybe I am missing something.
I noticed this issue https://github.com/rstudio/reticulate/issues/997 on the reticulate GitHub repository. Apparently, the automatic configuration through Config/reticulate only works if a conda environment is already loaded.
Therefore, I think the only way to configure the correct environment is on the .onLoad function:
check if Anaconda is installed, otherwhise launch the Miniconda installation through reticulate::install_miniconda()
check if the environment is already present, otherwise create create it through reticulate::conda_create(envname),
install the Python dependencies if necessary through reticulate::conda_install(envname, packages),
load the configured environment.
In this way, the first time the package is loaded, the environment will be correctly created.
After that, the environment will be automatically loaded.
I am trying to load/read a ply file using PyMesh and this line command:
mesh = pymesh.load_mesh("model.obj")
as it is in http://pymesh.readthedocs.io/en/latest/basic.html.
But this gives me an error "AttributeError: 'module' object has no attribute 'load_mesh'".
Am I doing anything wrong? Also I want to know if PyMesh really allows to visualize in 3d the objects.
Thank you.
If you installed with pip, you might not have gotten the pymesh module you were intending to use. Since you're looking for the load_mesh() method, you'll want to use this installation guide: http://pymesh.readthedocs.io/en/latest/installation.html.
There are actually two modules named pymesh.
Pymesh by Takuro Wada
If you install pymesh using pip you are installing this one which has the following GitHub page.
It reads: .sty and .obj
Pymesh by Qingnan Zhou
If you want to install http://pymesh.readthedocs.io/en/latest/ you have to follow the installation guidelines here.
It is more complex, I never manage to get it working, but it should read also .ply.
On a side note, meshio (one of my projects) now supports PLY as well. Install with
pip3 install meshio
and use on the command line like
meshio-convert in.ply out.vtk
or from within Python like
import meshio
mesh = meshio.read("in.ply")
# mesh.points, mesh.cells, ...
Since you are look for load_mesh() method, i think that you are looking for this library.
This is the related doc.
If true, you have to install pymesh2
pip install pymesh2
Otherwise you have to follow the instructions contained in that page as already suggested, but they are more complex.
Either you have not imported the pymesh library
import pymesh
OR
You have a file named pymesh.py in your directory where you are executing this file.
If this is the case, then rename the file to some other name.
I've been having a ton of trouble using LXML, after installing it from https://pypi.python.org/pypi/lxml/3.2.1 using Easy_Install-2.7. I installed it on Windows using cygwin, and at first the package seemed to be okay. However upon further testing I ran into problems.
When I run code with:
import lxml
it works completely fine. But as soon as I try:
import lxml.etree
I get this error:
Traceback (most recent call last):
File "D:\Nick_Code\NewsScraper\testdummy.py", line 7, in <module>
import lxml.etree
File "/usr/lib/python2.7/site-packages/lxml-3.2.0-py2.7-cygwin-1.7.20-i686.egg/lxml/etree.py", line 7, in <module>
__bootstrap__()
File "/usr/lib/python2.7/site-packages/lxml-3.2.0-py2.7-cygwin-1.7.20-i686.egg/lxml/etree.py", line 6, in __bootstrap__
imp.load_dynamic(__name__,__file__)
ImportError: Permission denied
I've been trying to find information/work arounds for quite a while but no success. Please let me know if you have any insight or need information.
Thanks!
Michael
This is not a solid answer. But I will highlight several of the problems involved for obtaining a solution. Most likely the problem above, is like a cancer caused by several factors acting catastrophically together.
I have the same exact problem as in the OP, when attempting to use the native Cygwin supplied Python packages on my Windows Vista machine. Being new to Python I have spent several days in trying to get this to work, and understand why it is not working. But all my Google-fu returned nothing but countless dead ends. So here's my take on this.
There are many reasons why Python could have trouble under Cygwin, some which you can do something about and some which are beyond most peoples control. What it boils down to, are the following key issues:
Windows is a complete mess when it comes to file permissions, and Cygwin cannot handle windows file permissions very well. So what you see in Cygwin is far from the whole story.
Windows is shamefully character case-independent which causes loads of trouble, especially when you need to (cross)compile anything that was originally developed under *nix based system (i.e. everything). In fact, if you attempt extracting any archive that contains files whose names differ only in capitalization. (I.e. "makefile" vs "Makefile" etc.) files under Windows or Cygwin, you loose all but one of the files. in case their You need to enable case-sensitivity to do anything more than "hello world" *nix compilations.
Windows handles symlinks completely different than Cygwin. And if your ZIP, TAR etc. archives contain any symlinks, they will be broken after extraction to Windows environment.
Sloppy code practices, where developer have not properly tested their creations on various environments, or carefully set proper file permissions to their *.tar.gz collections. Including correct dependency specifications, or mentioning whether or not binaries has been statically linked etc.
For the full gory details and further (Win-Cygwin) issues, look HERE.
At first I tried to use Cygwin's own Python without any additional packages, and nstalling lxml using PIP and easy_install. Then I tried to use Cygwin's own libxml2, libxslt and xml python packages, and I had the same problems.
At first, after installing the static windows binaries (as suggested elsewhere),
I got this error:
File "/usr/lib/python2.7/site-packages/lxml-3.2.4-py2.7-cygwin-1.7.24-i686.egg/lxml/etree.py", line 6, in __bootstrap__
imp.load_dynamic(__name__,__file__)
ImportError: Permission denied
Aborted (core dumped)
Then I investigated the file permissions and changed those with: chmod -R 755 /usr/lib/python2.7/
I got one step further to isolate problem to an apparently missing file.
And enabling verbose and diagnostic mode's didn't help much either.
File "/usr/lib/python2.7/site-packages/lxml-3.2.4-py2.7-cygwin-1.7.24-i686.egg/lxml/etree.py", line 6, in __bootstrap__
imp.load_dynamic(__name__,__file__)
ImportError: No such file or directory
Aborted (core dumped)
HERE is the exact statement specification:
Load and initialize a module implemented as a dynamically loadable shared
library and return its module object. If the module was already initialized, it
will be initialized again. Re-initialization involves copying the __dict__
attribute of the cached instance of the module over the value used in the module
cached in sys.modules. The pathname argument must point to the shared library.
The name argument is used to construct the name of the initialization function:
an external C function called initname() in the shared library is called. The
optional file argument is ignored. (Note: using shared libraries is highly
system dependent, and not all systems support it.)
So I started reading on the lxml website which clearly state lxml's dependencies on both libxml2 and libxslt, and unless they are statically linked, they also depend on iconv and zlib. So you're lead to believe you need to install all of these. Don't! Continue reading. But if you're going to build from sources (as easy_install may try to do) you'll need everything, including the development header libraries: libxml2-devel, libxslt-devel. Another place states that you also need Cython and install with:
easy_install lxml==dev
The dependencies are shown in this picture from HERE:
So you think you may get away with something like:
STATIC_DEPS=true pip install lxml
But that doesn't do it either. Probably because the libraries used to compile Cygwin's Python have to be the same as those for compiling lxml. But I don't know. Notice how the lxml package refers to Cygwin "1.7.24". My Cygwin is already "1.7.25" and you can check this with uname -a. Then you can check your static python executable with file and ldd. Then you understand that this also depend on the C-compiler used for building python/cygwin under Windows or *nix. Smelling a nightmare I decided that building my own was not the way to go. So next I tried to install the Python libraries (supplied as
executables) meant for Windows Python. This didn't work since I never had windows native Python installed, and I was greeted with an error that the installed could not find Python in my registry. I could of course just extract the executable, but I wouldn't know where to put the binaries without the installer. So I had another idea...
There are 3 possible solutions to getting this to work, as far as I can see.
The easy way of installing a Windows native Python interpreter. You loose some native Cygwin functionality, unless you install in correct place: /usr/lib/python2.7 and make sure Cygwin can find it and use it. This also uses a different file-permissions, case-sensitivity and character set (UTF-16LE) than Cygwin (UTF-8), potentially creating many other issues down the line! Difficulty: Easy
Continue hacking the Cygwin's Python, to make it work with the binary libraries used in (1). But this requires:
a) Uninstall and remove all Cygwin Python packages, except bare Python interpreter.
b) Remove all PIP and easy install traces.
c) Hacking the Windows registry to pretend to have Python27 installed:
HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.7\InstallPath C:\Python27\
HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.7\PythonPath C:\Python27\Lib;C:\Python27\DLLs;C:\Python27\Lib\lib-tk
HKEY_CLASSES_ROOT...
d) Install the Windows binary libraries.
e) All the rest should now hopefully work with PIP or easy_install. Difficulty: Medium!
Doing it properly by compiling Python and all libraries from scratch. Difficulty: Hard!
I successfully did (1), but I still think (2) is the smarter way of doing it, but I have not tested it, which is why I don't consider this as a good answer. BTW. One more quirk, I have to run the interpreter with: python.exe -E to avoid an annoying: "SyntaxError: invalid syntax" when hitting return!
Conclusion:
Apparently, you don't need the libxml2 and libxslt python packages to use lxml!
In my case I needed Scrapy, so I also had to install a few other packages.
$ pip.exe list
cssselect (0.9.1)
lxml (3.2.4)
pip (1.4.1)
pyOpenSSL (0.11)
pywin32 (218)
queuelib (1.1.1)
Scrapy (0.20.0)
setuptools (1.4.1)
six (1.4.1)
Twisted (13.2.0)
w3lib (1.5)
zope.interface (4.0.5)
$ll /cygdrive/c/Python27/Lib/site-packages/
adodbapi
cssselect
isapi
lxml
OpenSSL
pip
pythonwin
pywin32_system32
queuelib
scrapy
twisted
w3lib
win32
win32com
win32comext
zope
cssselect-0.9.1-py2.7.egg-info
lxml-3.2.4-py2.7.egg-info
pip-1.4.1-py2.7.egg-info
queuelib-1.1.1-py2.7.egg-info
Scrapy-0.20.0-py2.7.egg-info
six-1.4.1-py2.7.egg-info
Twisted-13.2.0-py2.7.egg-info
w3lib-1.5-py2.7.egg-info
zope.interface-4.0.5-py2.7.egg-info
PyWin32.chm
setuptools-1.4.1-py2.7.egg
pyOpenSSL-0.11-py2.7.egg-info
pywin32-218-py2.7.egg-info
easy-install.pth
pywin32.pth
setuptools.pth
zope.interface-4.0.5-py2.7-nspkg.pth
pythoncom.py
six.py
pythoncom.pyc
six.pyc
pythoncom.pyo
pywin32.version.txt
README.txt
Useful References:
HERE
HERE
HERE HERE HERE HERE
HERE
I'm Python newbie, Recently, I am working a project on JIRA. I need to access JIRA api to retreive some info about issues. But it always indicates as follows:
WARNING: Couldn't import magic library (is libmagic present?) Autodetection of avatar image content types will not work; for create_avatar methods, specify the 'contentType' parameter explicitly.
And in fact, when I download the magic package with easy_install or pip, it always fail.
And then, I download the libmagic and magic package manually, copy them to the directory C:\Python27\Lib\site-packages, but when executing the clause jira = JIRA(), it still produces the warning as mentioned above
If it is asking for magic and libmagic it means libmagic is not installed, not just the python bindings for it. You need to install that via your package manager from your OS.
Also, if you need help, we can't really help you without tracebacks, so if you're getting errors you need to include those.