I have a script of the following shape:
main.py
utilities/
__init__.py
foo.py
In main.py I import the function bar from foo.py:
from utilities.foo import bar
However, Travis cannot import this, returning:
ModuleNotFoundError: No module named 'utilities.foo'
How can I solve this?
I don't understand how or why, but changing the name of the utilities folder to utils solves the issue.
Related
My Folder Structure looks like the following
person-package
|- __init__.py
|- person.py
|- person_manager.py
main.py
person_manager.py imports person.py
import person as x
The main.py imports person_manager.py
import person_package.person_manager as x
When running main.py I get:
ModuleNotFoundError: No module named 'person'
I know, I could solve that by changing the import of person_manager.py to the following
from . import person as x
However, when running now person_manager.py directly, I get:
ImportError: attempted relative import with no known parent package
So I can't test person_manager.py on its own.
What is the most elegant way to solve that?
1. I recommend to always use absolute imports (unless strictly impossible).
2. person-package is not a valid Python name since it contains a dash -, if I were you I would rename to person_package with an underscore _.
3. Since person_manager.py is part of a Python importable package (i.e. it is in a directory containing a __init__.py file), then it should not be run as python person_package/person_manager.py, but as python -m person_package.person_manager.
I'm trying to create a package (that includes several subpackages) for reuse and distribution. The plan is to provide a CLI entry point to allow easy launch. After building the package and installing it in a virtualenv, I get a ModuleNotFoundError for imports from the subpackages included in the main package.
I think this has something to do with setting the right paths in __init__.py, but having read multiple examples on the web, I'm still rather confused as to why anything should go in __init__py and what that something is.
The package is built so that the package name (and thus folder created in site-packages) is the same as the root in the directory structure below.
The directory structure is (simplified and with names changed):
mypackage
|- __init__.py
|- entrypoint.py
|- subpackage1
|-- __init__.py
|-- module1.py
|- subpackage2
|-- __init__.py
|-- module2.py
Note that all the __init__.py are empty
And entrypoint.py is:
from subpackage1.module1 import foo
from subpackage2.module2 import baz
if __name__ == "__main__":
pass
In my pyproject.toml, I define:
\[project.scripts\]
mypackage-cli = "maypackage:entrypoint"
After installing with pip, I run (in a virtualenv where I pip installed the package):
(myvenv) me#mymachine ~ % mypackage-cli
But I get:
ModuleNotFoundError: No module named subpackage1
Two things to note:
When running source locally, I have no issues
If I edit the files in site-packages to have from mypackage.subpackage1.module1 import foo I don't get the error anymore when running the installed package, but then when trying to run the same modified imports (i.e. changing to import mypackage.subpackage1.module1) locally in my dev env, I get a ModuleNotFoundError
What's the correct way to get the imports to work when packaged and when running locally in my dev env?
Thanks!
Your "top-level importable package" seems to be mypackage so all your import statements should start from there. For example from mypackage.subpackage1.module1 import foo.
In order to avoid confusion between "local" and "installed" (in site-packages), I recommend you to use the so-called "src-layout" for this project's directory structure. In combination with the "editable" installation, it is very convenient to work with.
I'm trying to create a simple web app with Dart.
But I cannot import anything that is outside the current or in a sub directory. I'm using VSCODE
My project structure:
/chatapp
/web
/main.dart
/bin
/server.dart
/views
/view.dart
/chatsignin.dart
Now I can import view.dart in chatsignin.dart but cannot import view.dart to main.dart or bin/server.dart. Or any of the other file to any other file in a different directory.
I tried import with package name:
import 'package:chatapp/';
But it shows no subdirectories or files in VS Code
I tried pub get and restarted vscode multiple times but it doesn't work.
After reading the docs I found that all files and folders should be inside the web directory.
I'm embarrassed of myself doing such a silly mistake
ci professionals,
I cannot figure out why this code cannot find the shared library. Please see the log
https://pastebin.com/KvJP9Ms3
[31mImportError while importing test module '/home/travis/build/alexlib/pyptv/tests/test_pyptv_batch.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_pyptv_batch.py:1: in <module>
from pyptv import pyptv_batch
pyptv/pyptv_batch.py:20: in <module>
from optv.calibration import Calibration
E ImportError: liboptv.so: cannot open shared object file: No such file or directory[0m
!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!
[1m[31m=========================== 1 error in 0.43 seconds ============================[0m
the pull request
https://github.com/alexlib/pyptv/pull/4
and the build https://travis-ci.org/alexlib/pyptv/builds/342237102
We have a C library (http://github.com/openptv/openptv) that we need to compile and using Cython bindings add to Python, then we use Python through bindings. The tests work locally but not on Travis-CI (great service). I think it's a simple issue with paths, but I couldn't figure out how to deal with this.
Thanks in advance
Alex
The answer I have found was to set also the DYLD_LIBRARY_PATH that is required on Mac OS X:
export PATH=$PATH:/usr/local/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/usr/local/lib
I am trying to run object recognition kitchen adn to do mesh_object but when I run
rosrun object_recognition_reconstruction mesh_object --all --visualize --commit
I get this:
import ecto_image_pipeline.conversion
ImportError: No module named conversion
I found somewhere that I have to add the ecto_image_pipeline ros package to my local workspace and build the module by hand but I don't know how to do it. Can anyone help me please?