Django ImportError: No module named 'app' - python-3.4

I have been using django 1.3 by now. But wanted to start with latest version 1.8.1 with python3.4I have started with the project.
Here is my directory structure:
├── myapp
│   ├── common
│   │   ├── admin.py
│   │   ├── __init__.py
│   │   ├── migrations
│   │   │   └── __init__.py
│   │   ├── models.py
│   │   ├── tests.py
│   │   └── views.py
│   ├── __init__.py
│   ├── __pycache__
│   ├── settings.py
│   ├── templates
│   │   └── home.html
│   ├── urls.py
│   └── wsgi.py
└── manage.py
*urls.py
from django.conf.urls import include, url
from django.contrib import admin
from . import views
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^$', "home", name='homepage'),
]
views.py
from django.shortcuts import render
def home(request):
render(request, "home.html", {"text":"Hello World!!!"})
settings
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'common',
)
Getting following error on runserver
$ python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.4/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.4/site-packages/django/core/management/__init__.py", line 312, in execute
django.setup()
File "/usr/local/lib/python3.4/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.4/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/usr/local/lib/python3.4/site-packages/django/apps/config.py", line 86, in create
module = import_module(entry)
File "/usr/local/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2224, in _find_and_load_unlocked
ImportError: No module named 'common'

The path of manage.py looks unusual to me. manage.py is usually at the top level project directory. The problem you encounter stems from the fact that django roots the search path (i.e. sys.path) at the path of the manage.py script.
In your case, common's relative module path is actually myapp.common.
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myapp.common',
)
Of course myapp is then actually the project in django lingo.

Related

Airflow Failed To Import Plugin for a plugin folder with custom name

I have to work on a shared Airflow 1.10 project, so I have cloned the repository and the structure is as follow:
airflow
├── airflow.cfg
├── airflow.db
├── dags
│   ├── dags_here.py
│     
├── dags_conf
│   ├── some settings for dags
│   │   └── settings.py
│   │   ├── __init__.py
│   │   ├── settings.py
│   │   └── todo.txt
| |__ init.py
|
├── utilities
│   ├── __init__.py
│   └── some_name
│   ├── airflow
│   │   └── hooks.py
└── sensors.py
└── plugins.py
│   ├── common
│   │   ├some_other_code_files.py
│   ├── __init__.py
|
├── README.md
├── unittests.cfg
└── venv
├── lib64 -> lib
└── pyvenv.cfg
But when I try to list dags I face this error:
plugins_manager.py:225} ERROR - No module named 'common' Traceback
(most recent call last): File
"/home/xxx/venv/lib/python3.8/site-packages/airflow/plugins_manager.py",
line 218, in
m = imp.load_source(namespace, filepath) File "/usr/lib/python3.8/imp.py", line 171, in load_source
module = _load(spec) File "", line 702, in _load File "", line 671, in
_load_unlocked File "", line 783, in exec_module File "", line 219,
in _call_with_frames_removed File
"/home/xxx/airflow/utilities/xxx/common/insert_obj.py", line 3, in
from common.xxxxx import Class_name ModuleNotFoundError: No module named 'common' [2021-05-30 23:13:05,933] {plugins_manager.py:226}
ERROR - Failed to import plugin
/home/xxxx/airflow/utilities/xxxxx/common/dag_file.py
I have tried below configs inside may airflow.cfg but always the same error:
plugins_folder=/home/xxx/airflow/utilities
Adding a parent directory inside Airflow folder called plugins with an __init__.py file and copying utilities inside that:
plugins_folder=/home/xxx/airflow/plugins
confirm how the environment variables that Airflow uses or the airflow.cfg settings are configured.
environment variables
AIRFLOW_HOME=<YOUR_PROJ>
AIRFLOW__CORE__DAGS_FOLDER=$AIRFLOW_HOME/dags
AIRFLOW__CORE__PLUGINS_FOLDER=$AIRFLOW_HOME/utilities
airflow.cfg
dags_folder = {AIRFLOW_HOME}/dags
plugins_folder = {AIRFLOW_HOME}/utilities
Also, see what is configured in PYTHONPATH:
import sys
from pprint import pprint
pprint(sys.path)
# [
# '/ssddisk/project_name/dags',
# '/ssddisk/project_name/config',
# '/ssddisk/project_name/utilities',
# ...
# ]
See documentation for more details: https://airflow.apache.org/docs/apache-airflow/stable/howto/custom-operator.html#creating-a-custom-operator

How to apply Artifactory Permission Target to pip, and other non-human-predicatable/readable repo's?

To make Artifactory as self-service as possible for our users, giving permissions to users to deploy to parts of repositories using their personal or team accounts, I'm trying to figure out how to configure this.
For readable directory structure based repositories like anything in the java world, the Permission Targets work perfectly (https://www.jfrog.com/confluence/display/RTF/Managing+Permissions). But I can't find any docs on how to use this for non-human-predicatable/readable directory structures, like PIP, or the flat directory structure, like NPM.
In the java world, repositories have a nicely structured tree like:
~/.m2/repository$ tree org/ | head -20
org/
├── antlr
│   ├── antlr4-master
│   │   └── 4.7.1
│   │   ├── antlr4-master-4.7.1.pom
│   │   ├── antlr4-master-4.7.1.pom.sha1
│   │   └── _remote.repositories
│   └── antlr4-runtime
│   └── 4.7.1
│   ├── antlr4-runtime-4.7.1.jar
│   ├── antlr4-runtime-4.7.1.jar.sha1
│   ├── antlr4-runtime-4.7.1.pom
│   ├── antlr4-runtime-4.7.1.pom.sha1
│   └── _remote.repositories
├── apache
│   ├── ant
│   │   ├── ant
│   │   │   ├── 1.10.1
│   │   │   │   ├── ant-1.10.1.jar
│   │   │   │   ├── ant-1.10.1.jar.sha1
For example, to give teamantl permission to only read, annotate, and write to org/antlr/antlr4-master/**, the following json can be PUT to Artifactory REST API (PUT /api/security/permissions/{permissionTargetName})
{
"includesPattern": "org/antlr/antlr4-master/**",
"repositories": [
"libs-release-local",
"libs-snapshot-local"
],
"principals": {
"groups" : {
"teamantl": ["r","n","w"]
}
}
}
But for example a pip repo is completely hashed:
Which is completely useless in the permission target "includesPattern".
How should this (Permission Targets) work for repo's like PIP, and NPM?
Your screenshot shows a virtual PyPI repo, which is generated and thus hash-structured.
Normally, these are backed by physical repos, filled using twine upload and thus having a ‹pkg›/‹version›/‹file› structure – i.e. perfectly usable as permission targets with package granularity.

Generate a list or map of css files

I'm starting to work on a new app at my company. I'm hoping to run a quick process that will generate an outline, tree, or other map-type thing of all of the CSS and SASS files in the app directory.
I know I can grep it, but I wanted to see if someone had something more targeted I could use.
If you're simply looking to generate a tree, the common tree command can filter by file type if provided a pattern. Maybe this will help:
tree -P "*.css" --prune
The -P option allows you to match a pattern, and the --prune option hides empty folders (or ones which don't contain match files).
It's a pretty nifty tool; here's some sample output from tree -P "*.js" --prune on a node project directory:
.
├── Authorize.js
├── collections.js
├── functions
│   ├── downloadImage.js
│   ├── generateThumbnails.js
│   ├── hashImage.js
│   ├── loadMedia.js
│   └── uploadFile.js
├── node_modules
│   ├── body-parser
│   │   ├── index.js
│   │   ├── lib
│   │   │   ├── read.js
│   │   │   └── types
│   │   │   ├── json.js
│   │   │   ├── raw.js
│   │   │   ├── text.js
│   │   │   └── urlencoded.js
│   │   └── node_modules
│   │   ├── bytes
│   │   │   └── index.js
│   │   ├── content-type
│   │   │   └── index.js
More documentation here: http://www.computerhope.com/unix/tree.htm

Custom grunt configuration

I'm porting an application from php to node(sailsjs) at the same time trying to replace ant with grunt. I like the current project build structure and I would like to preserve some of it.
It looks like below...
project root
├── build (git ignored)
│   ├── coverage
│   ├── dist(to be deployed to target env)
│   └── local(to be deployed to local env)
├── lib
│   └── some library files like selenium..etc.
├── src
│   ├── conf
│   │   └── target/local properties
│   ├── scripts(may not be needed with grunt??)
│   │   ├── db
│   │   │   └── create_scripts...
│   │   ├── se
│   │   │   └── run_selenium_scripts...
│   │   └── tests
│   │   └── run_unit_test_scripts...
│   ├── tests
│   │   └── test_code....
│   └── webapp(this is where I'd like to place node[sailsjs] code)
│      └── code....
└── wiki .etc...
It doesn't exactly have to be the same way as above but more or less I prefer to build something similar. Now, pretty much all the sailsjs examples I have seen look like below.
project root
├── .tmp
│   └── stuff...
├── package.json
├── tasks
│   ├── config
│   │   └── grunt task configs...
│   └── register
│      └── grunt task registrations...
├── tests
│   ├── unit
│   └── selenium
└── Gruntfile.js
Where should I place Gruntfile.js, app.js, package.json to achieve what I want? What other detail should I have to make grunt function and create artifacts as I want them?
Note: Obviously I'm not expecting to get all the details of grunt configuration. But I guess it helps to see where most important things go and how basic tasks could be configured.
Thanks for your answer.
It's hard to give a precise answer without a detail of your build steps, but I would suggest:
Gruntfile.js and package.json go to your root folder
you setup your individual build tasks (whatever they are) to output to build: see the doc of each task on how to do that, it's usually the dest option
Hope this helps a bit.

Compass and SASS on complex project structure

I'm developing an Angular application and I'm using the following folder structure:
.
├── app
│   ├── assets
│   │   ├── images
│   │   │   ├── brands
│   │   │   ├── coletaSeletiva
│   │   │   ├── quiz
│   │   │   └── vidaEmLem
│   │   │   └── avatars
│   │   ├── sass
│   │   └── stylesheets
│   ├── scripts
│   │   └── controllers
│   └── views
│   └── coleta
└── test
└── spec
└── controllers
This is the yeoman angular generated project.
The generated css that come from SASS is pointing to files with the following path '/app/assets/...', because config in at the project's root.
My server is starting from app folder, so I call my assets using just /assets/...
What should I do?
Should I place config.rb inside of app folder and change assets paths?
My config.rb looks like this:
http_path = "/"
css_dir = "app/assets/stylesheets"
sass_dir = "app/assets/sass"
images_dir = "app/assets/images"
javascripts_dir = "app/assets/javascripts"
relative_assets = true
You can minify your code with "grunt" or "grunt --force". Then i think there will be no issues.
If still you got the issue of images . Try to set the path like ../images/image.png [if image folder is in parent folder] or ./images/image.png [if image folder is in the same folder].

Resources