I have a small project which I want to depict the dependencies between the functions.
I tried using pydeps for this but when I do that I get a, very nice, diagram of the modules in the project but not how the functions interact.
This is how I invoke pydeps ...
pydeps --include-missing --show-deps --max-bacon 4 ./test/
Inside of ./test I have a set of python modules including an __init__.py.
I'm not even 100% sure that functional dependency depiction is what pydeps is meant to do ... the documentation only shows links between modules.
Can pydeps do this ? If not can something else do it ?
Things I've tried
I tried pycallgraph . Although I installed it in a pipenv environment I couldn't follow the directions without installing it using apt-get. When I then try to use it it complains it can't find 'pandas' which is installed within the pipenv environment but clearly not visible. I don't want to install pandas globally (which I assume would resolve this issue).
Tried pyan3 and got the message __init__() got multiple values for argument 'root'... which I wasn't sure how to interpret but is referenced here https://github.com/Technologicat/pyan/issues/64 without any useful resolution.
Related
I have a question regarding h5pyViewer to view h5 files. I tried pip install h5pyViewer but that didn't work. I checked on Google and it states that h5pyViewer does not work for older versions of Python, but that there are a few solutions on GitHub. I downloaded this with pip install git+https://github.com/Eothred/h5pyViewer.git which finally gave me a successful installation.
Yet, when I want to import the package with import h5pyViewer it gave me the following error: ModuleNotFoundError: No module named 'h5pyViewer'. However when I tried to install it again it says:
Requirement already satisfied: h5pyviewer in c:\users\celin\anaconda3\lib\site-packages (-v0.0.1.15)Note: you may need to restart the kernel to use updated packages.
Any ideas how to get out of this loop or in what other way I could access an .h5 file?
There could be so many things wrong so it's hard to say what the problem is.
The actual package import has a lowercase "v": h5pyviewer (as seen in your error message).
Your IDE/python runner may not be using your Conda environment (you can select the environment in VSCode, and if you are running a script in the terminal make sure your Conda env is enabled in that terminal)
The GitHub package might be exported from somewhere else. Try something like from Eothred import h5pyviewer.
Maybe h5pyviewer is not even supposed to be imported this way!
Overall, I don't suggest using this package, it seems like it's broken on Python 3 and not well maintained. The code in GitHub looks sketchy, and very few people use it. A good indicator is usually the number of people that star or use the package, which seems extremely low. Additionally, it doesn't even have a real readme file! It doesn't say how to use it at all. Suggest you try something else like pandas. But if you really want to go with this, you can try the above debugging steps.
I am aware that pip freeze > requirements.txt exists, yet that that prints out my system packages, of which only a few my directory/ project needs.
I am not using a virtualenv so I'm pretty sure I can't print out local packages like that.
I also know that pipdeptree exsists but I also don't see how that solves my problem?
I believe tools like the following could help:
pipreqs
pigar
As far as I can tell, these tools read the code in the directory and try to figure out the dependencies required based on the import statements they found in the code.
Related:
https://stackoverflow.com/a/61202584
https://stackoverflow.com/a/61540466
https://stackoverflow.com/questions/61143402/how-to-generate-requirements-txt-for-given-py-sources-folder-or-specific-py-file
https://stackoverflow.com/a/31684470
I'm running a code on deep learning, which uses the opencv module, by running python main.py (contains import cv2 statement), but always get the error 'ImportError: dynamic module does not define module export function (PyInit_cv2)'.
I've tried to reinstall my anaconda and create new virtual environments, but all got the same result. This problem really confuses me a lot and I've googled for many related problems, none of them works. I think the problem is something related to the environment and has nothing to do with the code, because I got the same result by simply run import cv2 in python prompt. The more confusing thing is that, even after I remove the opencv module, I also get the same problem, but not a ModuleNotFoundError. Does anyone can give me some advice? Thanks a lot!
I think I found one possible reason of this error.
Recently I was configuring the caffe environment on one server, I downloaded the source code of opencv-2.4.13 and compiled manually, added /usr/local/opencv-2.4.13/build/lib to $PYTHONPATH, and caffe worked well. After that, when I entered one of my virtual environment using conda activate py35, which uses python3.5, tried import cv2 in the python prompt, got the error above.
I'm not sure but I think the cause of the error is opencv-2.4.13 compiles a python2 interface so it can't be imported by python3. Python imports packages by searching the directories listed in sys.path, where $PYTHONPATH is in the second place after the current working directory (This is a great article introduces the mechanism of python finding packages). So when we enter the py35 environment, python will first look for $PYTHONPATH and find the opencv installed on the root directory instead of finding the opencv in the virtual environment using conda install opencv-python.
So there are two solutions of this problem:
Use python2 instead.
Remove /usr/local/opencv-2.4.13/build/lib from $PYTHONPATH.
which all work for me.
Similar post, might help:
ImportError: dynamic module does not define init function (initfizzbuzz)
Could you provide info on how you installed the CV module?
I had the same problem, which was caused by the cv2.so file in /usr/local/lib/python2.7/site-packages/cv2.so. After I deleted the file and use command sudo pip3 install opencv-python, it worked for python3.
Tl;dr I have been a dummy and messing with those things. I have been going to site_packages doing stuff I shouldn't have been doing and I have messed with my environment variables.... PATH.... PYTHONPATH.... I don't even know all of this stuff yet I have to research it more in depth. Bottom line is that when I'm trying to install a package using a package manager like pip to install opencv... it's installing fine supposedly but then I get the "no module named cv" error.
I tried importing cv and cv2.
I think I am having this problem because I have been messing with a lot of stuff I shouldn't have.
So how do I start a brand new slate?... I don't even know how many python versions I have...
I have two packages in the same namespace with tests, the structure is like this:
Package-1/namespace/__init__.py
Package-1/namespace/module1/__init__.py
Package-2/namespace/__init__.py
Package-2/namespace/module2/__init__.py
Package-2/tests/foo_test.py
Package 1 is properly installed using pip. Now Package 2 depends on Package 1, so foo_test contains the line
import namespace.module1
When I try to run nosetests ./tests/foo_test.py from the directory Package-2 I get an import error because Python complains that it did not find namespace.module1. I am quite sure that the problem is that it tries to search the path Package-2/namespace for the directory module1 which is of course not present. I would like Python to load module1 from the installed packages and not search for it in the current path.
I am not entirely sure, but I think that here a similar issue is explained but to my understanding this should have been fixed. Does anybody have an idea how to work around this? Or am I supposed to structure things differently?
There is a solution for this, at least in Python 3.3+. The __init__.py files that are present in Package-i/namespace/ have to be deleted. I don't understand exactly why that solves the problem but it works in my case...