I’m having problems with one module in my Visual Studio Core project. It is not being found. It generates this error:
File "C:\Users\danj\source\repos\project_django\comstockapt\comstockapt\urls.py", line 28, in
from comstockapt.email_accounts import views as email_views
ModuleNotFoundError: No module named 'comstockapt.email_accounts'
I’ve gone through many, many similar questions, but I can’t get it to work. I’m using the virtual environment. When I execute “python” in the terminal and then run ‘help(“modules email_accounts”)’ it shows the module with all of its files.
When I run help(“modules”), I see all of my modules listed in the response.
Here is my urls.py file within module comstockapt.comstockapt.
Here is my installed_apps:
I've checked environment variables, the virtual environment, the directory structure. What can I try next?
You should import views from email_accounts like this:
from email_accounts import views as email_views
Related
I am running the following code:
pyinstaller --onefile main.py
main.py looks like:
import sys
import os
sys.path.append(r'C:\Model\Utilities')
from import_pythonpkg import *
......
import_pythonpkg.py looks like:
from astroML.density_estimation import EmpiricalDistribution
import calendar
import collections
from collections import Counter, OrderedDict, defaultdict
import csv
....
By running the pyinstaller on main.py, main.exe file is created successfully.
But when I run main.exe it gives error with astroML. If I move astroML to main.py from import_pythonpkg.py, there is no error with astroML. Now I get error with csv.
i.e. if I change my main.py to look as:
import sys
from astroML.density_estimation import EmpiricalDistribution
import os
sys.path.append(r'C:\Model\Utilities')
from import_pythonpkg import *
......
The astroML error is no longer present when I run main.exe.
There is no error with import calendar line in import_pythonpkg.py at all.
I am not sure how to handle this random error with packages when running main.exe after pyinstaller run.
import_pythonpkg is located at r'C:\Model\Utilities'
Edit:
Error with main.exe looks as following even though the original main.py runs fine. Pyinstaller was even able to let me create the main.exe without error.
Traceback (most recent call last):
File "main.py", line 8, in <module>
File "C:\Model\Utilities\import_pythonpkg.py", line 1, in <module>
from astroML.density_estimation import EmpiricalDistribution
ImportError: No module named astroML.density_estimation
[29180] Failed to execute script main
I believe PyInstaller is not seeing import_pythonpkg. In my experience, when adding to the path or dealing with external modules and dlls, PyInstaller will not go searching for that, you have to explicitly tell it to do so. It will compile down to an .exe properly because it just ignores it, but then won't run. Check to see if there are any warnings about missing packages or modules when you run your PyInstaller command.
But how to fix it...If indeed this is the issue (which I am not sure that it is) you can try 3 things:
1) move that package into your working directory and avoid using sys.path.append. Then compile with PyInstaller to so see if this works, then you know the issue is that pyinstaller is failing to find import_pythonpkg. You can stop there if this works.
2) explicitly tell PyInstaller to look there. You can use the hidden-import tag when compiling with PyInstaller to let it know (give it the full pathname).
--hidden-import=modulename
for more info, check here: How to properly create a pyinstaller hook, or maybe hidden import?
3) If you use the spec file that PyInstaller creates, you can try adding a variable call pathex to tell PyInstaller to search there for things:
block_cipher = None
a = Analysis(['minimal.py'],
pathex=['C:\\Program Files (x86)\\Windows Kits\\10\\example_directory'],
binaries=None,
datas=None,
hiddenimports=['path_to_import', 'path_to_second_import'],
hookspath=None,
runtime_hooks=None,
excludes=None,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,... )
coll = COLLECT(...)
for more information on spec files: https://pyinstaller.readthedocs.io/en/stable/spec-files.html
(notice you can also add hiddenimports here)
This answer may also prove helpful: PyInstaller - no module named
It is about to module which loaeded on your computer. If your IDE is different from your environment, you have to load same modules on your device via pip. Check the modules on CMD screen and complete the missing modules.
Sometimes you must load the modules all IDEs on your device. In my case, there were two IDEs (pycharm and anaconda). I used pycharm but pyinstaller used anaconda's modules so i unistalled anaconda and tried again. now it works..
I am trying to create an EXE using py2exe for a desktop app I wrote with python 2.7.
The app utilizes ibm_db (v2.0.7), which installs to site-packages as an .egg folder.
The contents of the ibm_db.py file are very short, as the logic itself is implemented in the DLL:
import os
if 'clidriver' not in os.environ['PATH']:
os.environ['PATH'] = os.environ['PATH'] + ";" + os.path.join(os.path.abspath(os.path.dirname(__file__)), 'clidriver', 'bin')
def __bootstrap__():
global __bootstrap__, __loader__, __file__
import sys, pkg_resources, imp
__file__ = pkg_resources.resource_filename(__name__,'ibm_db_dlls\ibm_db.dll')
__loader__ = None; del __bootstrap__, __loader__
imp.load_dynamic(__name__,__file__)
__bootstrap__()
When I ran py2exe on the project, the dependency on ibm_db wasn’t properly handled (the DLL wasn’t taken into the dist), so running the exe file stumbles upon the following error:
...
File "ibm_db.pyc", line 10, in <module>
File "ibm_db.pyc", line 6, in __bootstrap__
ImportError: No module named pkg_resources
I tried to copy the DLL manually into the dist folder (both directly and under ibm_db_dlls subfolder), but it’s of no use.
I found this page, and realized that py2exe has an issue with eggs:
http://www.py2exe.org/index.cgi/ExeWithEggs
As far as I understand, unzipping the egg is not the way to go in my case, because my program does use pkg_resources (through ibm_db.py). Still, I tried installing ibm_db via easy_setup with the --always-unzip option, but the installation gave me this error:
Not a URL, existing file, or requirement spec: '--always-unzip'
and it was still installed as an .egg.
So I’m looking at the “Including .egg files in your dist directory” option, and wondering whether it can help. And if so – where to start?
I’m using this simple setup.py for running py2exe:
from distutils.core import setup
import py2exe
setup(console=['MyApp.py'])
What is this “TurboGears” mentioned there? It doesn’t look like something I’m using in my app.
Any advice will be appreciated.
Thanks.
I am just getting started with PyCharm and have imported a project from Eclipse.
Running on a virtual env, I was able to register a compiled pyd file (PresPy). However, I still have an "unresolved reference" error. I also installed colormath from the PyCharm tooltip recommendation.
When running the project I strangely do not have the pyd-related error. Instead, the interpreter complains about a different module and not on the 'package level'.
Error 1
Unresolved reference: 'rgb_color' in import statement:
# These 4 lines work fine
import copy
import random
from math import pi, degrees
from configuration import Color, Condition # From custom package
import colormath.color_diff
from PresPy import rgb_color # Refers to a .pyd.
Error 2
Stack trace:
....
File "x:\proj\src\color_logic\palette.py", line 14, in <module>
import colormath.color_diff
ImportError: No module named colormath.color_diff
Process finished with exit code 1
Content root is the project folder. Source folders are in a separate /src/ folder. An incomplete setup.py stub is located in the content root. The project ran without errors from Eclipse on a different installation of pip install:ed packages.
Below, this returns the source root folder (from related answer):
import os
print os.getcwd()
Under Project: ... > Project Interpreter1 the packages colormath and PresPy are both listed.
1: PyCharm Community Edition 2016.2.3
Related: 1, 2
Solution: The Run configuration has to be changed to the corresponding virtual environment.
i am using pycharm with django. When i do the runserver command, my project starts up and everything is fine.
if i use the pycharm run command - that green arrow at the top - then i get problems.
The problems are:
runnerw.exe C:\development\python\python.exe manage.py runserver 127.0.0.1:8000
Traceback (most recent call last):
File "manage.py", line 11, in
import settings
File "C:\development\PycharmProjects\dumpstown\settings.py", line 185, in
add_to_builtins('gravatar.templatetags.gravatar')
File "C:\development\python\lib\site-packages\django\template\base.py", line 1017, in add_to_builtins
builtins.append(import_library(module))
File "C:\development\python\lib\site-packages\django\template\base.py", line 963, in import_library
raise InvalidTemplateLibrary("ImportError raised loading %s: %s" % (taglib_module, e))
django.template.base.InvalidTemplateLibrary: ImportError raised loading
gravatar.templatetags.gravatar: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
Process finished with exit code 1
And stem from my use of add_to_builtins here: (this is in the settings.py file)
#gravatar stuff here.
add_to_builtins('gravatar.templatetags.gravatar')
I know this is the problem, because if i remove this line in the settings.py file? everything works fine.
Is there a way to remedy this problem for pycharm?
You need to set your Django settings module in Settings | Django Support | Settings
http://www.jetbrains.com/pycharm/webhelp/django-support.html
UPDATED
The problem with django-gravatar is that it's templatetags import django.contrib.auth.models.User which relies on settings module while setting module is loaded in Django by DJANGO_SETTINGS_MODULE environment variable, which is set internally by execute_manager function call in manage.py, which is executed AFTER import of settings. So when you use undocumented add_to_builtins feature just in settings.py at that point you have no DJANGO_SETTINGS_MODULE env variable set. So that is not a problem of PyCharm, but a problem of unset environment variable and usage of undocumented Django feature add_to_builtin.
When I ran the same project from Unix console I get the same error.
Probably you have DJANGO_SETTINGS_MODULE set in your environment if it works from console.
So to make it work in PyCharm you need to set up the variable in Django run configuration.
You can read here about that (see Environment variable section).
As i answered here: https://stackoverflow.com/a/11299516/1061426
pycharm is broken and doesn't work with add_to_builtins. The two obvious solutions are:
don't use pycharm, use some free django plugins for eclipse, or old school text editing?
use pycharm, just don't use add_to_builtins. This is the route i've gone down - it is annoying fixing all the template's to import a module, but it was a lot simpler in my case than the hassle of porting across to a new IDE.
I am trying to move a django project to google appengine. So I followed http://code.google.com/appengine/articles/django.html . But
django.dispatch.dispatcher.connect(
log_exception, django.core.signals.got_request_exception)
django.dispatch.dispatcher.disconnect(
django.db._rollback_on_exception,
django.core.signals.got_request_exception)
was giving me error saying can't find dispatcher.connect/dispatcher.disconnect . So I changed the code as
django.dispatch.dispatcher.Signal.connect(
log_exception, django.core.signals.got_request_exception)
But now , when I am running the application , I am getting following error
*File "C:\Program
Files\Google\google_appengine\google\appengine\tools\dev_appserver.py",
line 2208, in ExecuteOrImportScript
exec module_code in script_module.dict File
"C:\Personal\Study\Python\twtApp\src\main.py",
line 23, in
import django.dispatch.dispatcher.Signal
ImportError: No module named Signal*
As it's said the google article , I have copied django folders to top level folder of my projects .
Is there anything I am missing ?
Pls help ..
Your issue lies in Python being unable to import the Signal module. Make sure it's properly in your path, and that it isn't somehow missing from your Django install.
I would strongly recommend that you use the google-app-engine-django project instead. You'll have a lot more luck.
http://code.google.com/p/google-app-engine-django/