Django informs me "ImportError: No module named pytz", but when I go to use pip to install it, I get this result:
Requirement already satisfied (use --upgrade to upgrade): pytz in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
Is it possible that it is looking in the wrong location, or that I need to try to install it somewhere else?
Here is the full stacktrace:
Internal Server Error: /basicloginwebservice/
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py", line 103, in get_response
resolver_match = resolver.resolve(request.path_info)
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py", line 321, in resolve
sub_match = pattern.resolve(new_path)
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py", line 223, in resolve
return ResolverMatch(self.callback, args, kwargs, self.name)
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py", line 230, in callback
self._callback = get_callable(self._callback_str)
File "/Library/Python/2.7/site-packages/django/utils/functional.py", line 29, in wrapper
result = func(*args)
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py", line 97, in get_callable
mod = import_module(mod_name)
File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/<redacted>/django/<redacted>/<redacted>/views.py", line 3, in <module>
import pytz
ImportError: No module named pytz
Thanks
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras is a location associated with the Apple-supplied Python 2.7 (/usr/bin/python2.7). It's not possible to tell from the traceback but chances are that Django is being run under a different instance of Python 2.7, perhaps linked to from /usr/local/bin. These sorts of problems can arise when there are multiple instances of Python and you are using pip directly from the command line. Make sure you have a version of pip installed for each Python you are using. And, to ensure that you are using the right instance of pip, you can invoke it this way:
python -m pip install pytz
substituting for python the same path that is used to run Django.
Another approach is to always use an activated virtualenv which should ensure that the right python and pip instances are found first on the process PATH.
Related
When i try to import numpy to my python file it says:
Traceback (most recent call last):
File "c:\src\Python\Raycast_Test_1\test.py", line 1, in <module>
import numpy as np
ModuleNotFoundError: No module named 'numpy'
(i just found some things in the pip help thingy so i did them and this is what i got)
and when i do pip search numpy this shows up:
ERROR: Exception:
Traceback (most recent call last):
File "c:\users\marti\appdata\local\programs\python\python38\lib\site-packages\pip\_internal\cli\base_command.py", line 224, in _main
status = self.run(options, args)
File "c:\users\marti\appdata\local\programs\python\python38\lib\site-packages\pip\_internal\commands\search.py", line 62, in run
pypi_hits = self.search(query, options)
File "c:\users\marti\appdata\local\programs\python\python38\lib\site-packages\pip\_internal\commands\search.py", line 82, in search
hits = pypi.search({'name': query, 'summary': query}, 'or')
File "c:\users\marti\appdata\local\programs\python\python38\lib\xmlrpc\client.py", line 1109, in __call__
return self.__send(self.__name, args)
File "c:\users\marti\appdata\local\programs\python\python38\lib\xmlrpc\client.py", line 1450, in __request
response = self.__transport.request(
File "c:\users\marti\appdata\local\programs\python\python38\lib\site-packages\pip\_internal\network\xmlrpc.py", line 46, in request
return self.parse_response(response.raw)
File "c:\users\marti\appdata\local\programs\python\python38\lib\xmlrpc\client.py", line 1341, in parse_response
return u.close()
File "c:\users\marti\appdata\local\programs\python\python38\lib\xmlrpc\client.py", line 655, in close
raise Fault(**self._stack[0])
xmlrpc.client.Fault: <Fault -32500: "RuntimeError: PyPI's XMLRPC API has been temporarily disabled due to unmanageable load and will be deprecated in the near future. See https://status.python.org/ for more information.">
and when i do pip check numpy this shows up:
No broken requirements found.
i have tried uninstaling the installing numpy but that didnt fix it.
How do i fix this?
(note i am using the vscode terminal for this)
pip install numpy --upgrade
or
pip install numpy --upgrade --ignore-installed
Just to make sure you are running correct pip, try running "pip -V" or "pip --version", it gives you which version of python it refers to. Its also possible that you might have pip for say python 2.7, pip3 for python 3.6, and pip3.7 for python 3.7, if you have multiple versions of python installed. For simplicity you can set the most frequently used pip version as pip by setting an alias in ~/.bashrc. This is done by adding the following line in bashrc:
alias pip=pip3.6.
After this you can try and install the packages and import it swiftly.
Traceback (most recent call last):
File "/usr/local/bin/airflow", line 25, in <module>
from airflow.configuration import conf
File "/usr/local/lib/python3.6/dist-packages/airflow/__init__.py", line 97, in <module>
operators._integrate_plugins()
File "/usr/local/lib/python3.6/dist-packages/airflow/operators/__init__.py", line 104, in _integrate_plugins
from airflow.plugins_manager import operators_modules, register_inbuilt_operator_links
File "/usr/local/lib/python3.6/dist-packages/airflow/plugins_manager.py", line 194, in <module>
plugins
File "/usr/local/lib/python3.6/dist-packages/airflow/plugins_manager.py", line 104, in load_entrypoint_plugins
plugin_obj = entry_point.load()
File "/home/ubuntu/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2460, in load
self.require(*args, **kwargs)
File "/home/ubuntu/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2483, in require
items = working_set.resolve(reqs, env, installer, extras=self.extras)
File "/home/ubuntu/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 791, in resolve
raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.ContextualVersionConflict: (tzlocal 2.1 (/home/ubuntu/.local/lib/python3.6/site-packages), Requirement.parse('tzlocal<2.0.0,>=1.4'), {'apache-airflow'})
**airflow was installed by colleagues from work, I first went to the server and the first thing I did was try to check its version
As far as I understand the problem may be due to two installed pythons-2.7 and 3.6 or because of the tzlocal version - but I don't know what it is**
the oddity is that the web muzzle raised by colleagues seems to work normally )) but commands from the console give me this
You have tzlocal package version 2.1 but apache-airflow requires tzlocal with version 1.4-2.0.0.
Downgrade your tzlocal to version 2.0.0:
pip install -Iv tzlocal==2.0.0
Note that if you have other software which uses tzlocal you may break it if it's not compatible with version 2.0.
pip freeze|grep tzlocal
tzlocal==1.5.1
self solved
Just updated my Mac to El Capitan 10.11.
I am trying to run Django 1.6 with Celery 3.1 and I'm getting this error now:
Unhandled exception in thread started by <function wrapper at 0x10f861050>
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/django/utils/autoreload.py", line 93, in wrapper
fn(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 101, in inner_run
self.validate(display_num_errors=True)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 310, in validate
num_errors = get_validation_errors(s, app)
File "/Library/Python/2.7/site-packages/django/core/management/validation.py", line 34, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/Library/Python/2.7/site-packages/django/db/models/loading.py", line 196, in get_app_errors
self._populate()
File "/Library/Python/2.7/site-packages/django/db/models/loading.py", line 75, in _populate
self.load_app(app_name, True)
File "/Library/Python/2.7/site-packages/django/db/models/loading.py", line 99, in load_app
models = import_module('%s.models' % app_name)
File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/Library/Python/2.7/site-packages/debug_toolbar/models.py", line 9, in <module>
dt_settings.patch_all()
File "/Library/Python/2.7/site-packages/debug_toolbar/settings.py", line 215, in patch_all
patch_root_urlconf()
File "/Library/Python/2.7/site-packages/debug_toolbar/settings.py", line 203, in patch_root_urlconf
reverse('djdt:render_panel')
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py", line 503, in reverse
app_list = resolver.app_dict[ns]
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py", line 329, in app_dict
self._populate()
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py", line 267, in _populate
for pattern in reversed(self.url_patterns):
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py", line 365, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py", line 360, in urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/Users/pedrotorres/Documents/work/projects/bparts/netpecasv2/urls.py", line 10, in <module>
url(r'', include('Common.urls')),
File "/Library/Python/2.7/site-packages/django/conf/urls/__init__.py", line 26, in include
urlconf_module = import_module(urlconf_module)
File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/Users/pedrotorres/Documents/work/projects/bparts/Common/urls.py", line 3, in <module>
from APIMobile.views import request_product_info_by_qrcode
File "/Users/pedrotorres/Documents/work/projects/bparts/APIMobile/views.py", line 9, in <module>
from Common.views import resizeImage, token_generator, getWatermarkImage, filterProductsByBrandModelVersionYear, \
File "/Users/pedrotorres/Documents/work/projects/bparts/Common/views.py", line 34, in <module>
from Common.tasks import turn_off_demo_mode_new_workshop
File "/Users/pedrotorres/Documents/work/projects/bparts/Common/tasks.py", line 3, in <module>
from netpecasv2.celeryapp import app
File "/Users/pedrotorres/Documents/work/projects/bparts/netpecasv2/celeryapp.py", line 5, in <module>
from celery import Celery
File "/Library/Python/2.7/site-packages/celery/__init__.py", line 130, in <module>
from celery import five
File "/Library/Python/2.7/site-packages/celery/five.py", line 51, in <module>
from kombu.five import monotonic
File "/Library/Python/2.7/site-packages/kombu/five.py", line 52, in <module>
libSystem = ctypes.CDLL('libSystem.dylib')
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
OSError: dlopen(libSystem.dylib, 6): image not found
Everything worked fine before.
Can't find a solution to fix this. I've seen this thread but doesn't work:
"OSError: dlopen(libSystem.dylib, 6): image not found" (OS X + macports + Celery 3.1.7)
I didn't have any DYLD_FALLBACK_LIBRARY_PATH before. I tried to:
export DYLD_FALLBACK_LIBRARY_PATH="/usr/lib":$DYLD_FALLBACK_LIBRARY_PATH
but Python can't find the Library despite it being located under "/usr/lib"
Anyone has had a problem like this?
I suspect (but can't confirm) the System Integrity Protection (SIP) of OSX El Capitan is preventing access to your /usr/lib folder.
It would be extreme and defeating the purpose of the security feature, but you could try disabling SIP by booting into the OS X Recovery partition, executing csrutil disable and rebooting...atleast until another option / work-around can be found.
ArsTechnica has a write-up here: http://arstechnica.com/apple/2015/09/os-x-10-11-el-capitan-the-ars-technica-review/9/
And a similar issue is described here: http://blog.honekamp.net/blog/2015/09/07/el-cap-and-my-printer/
More discussion on Hacker News here: https://news.ycombinator.com/item?id=10309576
pip install --upgrade billiard
pip install --upgrade celery
pip install --upgrade kombu
pip install --upgrade amqp
This should work.
I uninstall "billiard,celery,kombu,amqp" those four packages. Then reinstall the latest version from github solved this
I also ran into the same problem just after upgrading the OS to OS X El Captain. Disabling SIP does the trick, but if someone is not comfortable doing that updating five.py in few modules in site-packages will help. (I know it's not that nice, but it's OK as long as you know what you're doing)
Update the places that access the DLL to have absolute path in following modules
line 145 of site-packages/amqp/five.py
line 52 of site-packages/kombu/five.py
line 42 of site-packages/billiard/five.py
update to:
libSystem = ctypes.CDLL('libSystem.dylib') => libSystem = ctypes.CDLL('/usr/lib/libSystem.dylib')
hope this helps ;)
I ran into the same issue getting celery to work.
I did some quick tests and here's what I found, but can't quite pin it on a specific cause yet:
a. stock python with ctypes.CDLL("libSystem.dylib") results in the image not found error.
b. stock python with ctypes.CDLL("/usr/lib/libSystem.dylib") works
c. virtualenv python with ctypes.CDLL("libSystem.dylib") works
Reinstalling python solved the issue for me. Using brew you can just brew install python again. If it says that you need permission to write to /usr/local, try to change permissions by sudo chown -R $(whoami):admin /usr/local, and then install python.
I tried updating to the latest versions of these libraries from github, but it did not help. The simplest solution that I've found is to use virtualenv
virtualenv myenv
cd myenv
source bin/activate
pip install celery
To confirm it worked:
python -c "import celery"
This seems preferable to disabling a fundamental security feature of the OS, and virtualenv has its own (well documented) benefits.
You can delete the current celery version, and then download it from the http://pypi.python.org/pypi/celery/, build and install the sorce code.It is helpful for me, and I hope so do you.
In my case, the error is because Homebrew was not symlink to gettext properly. I've solved this using
brew unlink gettext && brew link --force gettext
copying from How to install h5py (needed for Keras) on MacOS with M1?
in case someone ended up here first like I was and wants to avoid disabling SIP. this seems to work for me:
brew install hdf5#1.10
export HDF5_DIR=/usr/local/Cellar/hdf5#1.10/1.10.7_1
pip install 'h5py==2.10.0' --force-reinstall --no-binary=h5py
1 . Install Homebrew as macOS Sur is missing the necessary ODBC package
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
2 . Install missing ODBC package
brew install libiodbc
After I installed PyReadline, IPython won't work. When I uninstalled it, it starts working again.
The stack trace for ipython:
(py2.7_monitor)[root#vm10-136-8-98 monitor]# ipython
WARNING: IPython History requires SQLite, your history will not be saved
Traceback (most recent call last):
File "/home/py2.7_monitor/bin/ipython", line 11, in <module>
sys.exit(start_ipython())
File "/home/py2.7_monitor/lib/python2.7/site-packages/IPython/__init__.py", line 118, in start_ipython
return launch_new_instance(argv=argv, **kwargs)
File "/home/py2.7_monitor/lib/python2.7/site-packages/traitlets/config/application.py", line 591, in launch_instance
app.initialize(argv)
File "<string>", line 2, in initialize
File "/home/py2.7_monitor/lib/python2.7/site-packages/traitlets/config/application.py", line 75, in catch_config_error
return method(app, *args, **kwargs)
File "/home/py2.7_monitor/lib/python2.7/site-packages/IPython/terminal/ipapp.py", line 314, in initialize
self.init_shell()
File "/home/py2.7_monitor/lib/python2.7/site-packages/IPython/terminal/ipapp.py", line 330, in init_shell
ipython_dir=self.ipython_dir, user_ns=self.user_ns)
File "/home/py2.7_monitor/lib/python2.7/site-packages/traitlets/config/configurable.py", line 380, in instance
inst = cls(*args, **kwargs)
File "/home/py2.7_monitor/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 531, in __init__
self.init_readline()
File "/home/py2.7_monitor/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 1941, in init_readline
import IPython.utils.rlineimpl as readline
File "/home/py2.7_monitor/lib/python2.7/site-packages/IPython/utils/rlineimpl.py", line 21, in <module>
_rl = __import__(_rlmod_name)
File "/home/py2.7_monitor/lib/python2.7/site-packages/readline.py", line 6, in <module>
from pyreadline.rlmain import Readline
File "/home/py2.7_monitor/lib/python2.7/site-packages/pyreadline/__init__.py", line 12, in <module>
from . import logger, clipboard, lineeditor, modes, console
File "/home/py2.7_monitor/lib/python2.7/site-packages/pyreadline/clipboard/__init__.py", line 13, in <module>
from .win32_clipboard import GetClipboardText, SetClipboardText
File "/home/py2.7_monitor/lib/python2.7/site-packages/pyreadline/clipboard/win32_clipboard.py", line 37, in <module>
import ctypes.wintypes as wintypes
File "/usr/local/lib/python2.7/ctypes/wintypes.py", line 23, in <module>
class VARIANT_BOOL(_SimpleCData):
ValueError: _type_ 'v' not supported
As stated on their site, the PyReadline library is Used for Windows.
Looking at the last lines of your stack trace:
import ctypes.wintypes as wintypes
File "/usr/local/lib/python2.7/ctypes/wintypes.py", line 23, in <module>
class VARIANT_BOOL(_SimpleCData):
ValueError: _type_ 'v' not supported
It is trying to import windows specific data types from ctypes which is obviously not possible since you are not running Windows.
This will likely help exactly no one in the year 2020 or beyond, but all the same I want to record it here for posterity.
I experienced the same ValueError: _type_ 'v' not supported traceback with an installation of Python 2.7.16 in an HPC cluster environment, attempting to install pdbpp, which depends on fancycompleter, which depends on pyreadline, which imports ctypes.wintypes and is affected by this this core Python issue from 2012.
It's true that ctypes.wintypes should never be imported on a non-Windows platform (Cygwin, MSYS2, and Git Bash are technically non-Windows, since they will have a real GNU Readline library and don't need the pure Python shim).
However if it were imported on a non-Windows platform, because of the issue mentioned above, ctypes.wintypes throws a ValueError instead of an ImportError, which means that a typical try/except that expects to catch an ImportError will just blow up because of the unhandled exception.
Pdbpp's fancycompleter, or rather pyreadline, somehow fell victim to this. I get confused about who's to blame, because fancycompleter's setup.py isn't supposed to bring in pyreadline as a dependency except on Windows, but somehow there it was on my Linux system. And if it's there, fancycompleter tries to import it.
All I can figure is I may have had an old fancycompleter in my pip cache with a typo in its setup.py that was pulling in pyreadline when it shouldn't have, because it was grabbing that dependency, time after time.
What actually finally resolved this situation for me was to pip uninstall pyreadline, then pip install -U --ignore-installed --no-cache-dir fancycompleter to get a "fresh" version of fancycompleter that did not bring in the unnecessary pyreadline dependency.
OSX, Python 2.7, pip, virtualenv. Been using these for years with no issues.
I'm not sure what changed, but recently my environment completely broke for Django after working perfectly fine for a while. The same checkout runs fine on my friend's computer with a similar setup.
Things I've already tried: deleting my venv and creating a new one with fresh installs from requirements.txt, uninstalling logging outside the venv and reinstalling inside, reinstalling pip.
I get the same traceback for any manage.py command. It appears to be having issues with the logging module:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/rfong/Dropbox/code/lattis_workspace/lattis_repo/venv/lib/python2. 7/site-packages/django/core/management/__init__.py", line 453, in execute_from_command_line
utility.execute()
File "/Users/rfong/Dropbox/code/lattis_workspace/lattis_repo/venv/lib/python2. 7/site-packages/django/core/management/__init__.py", line 376, in execute
sys.stdout.write(self.main_help_text() + '\n')
File "/Users/rfong/Dropbox/code/lattis_workspace/lattis_repo/venv/lib/python2. 7/site-packages/django/core/management/__init__.py", line 242, in main_help_text
for name, app in six.iteritems(get_commands()):
File "/Users/rfong/Dropbox/code/lattis_workspace/lattis_repo/venv/lib/python2. 7/site-packages/django/core/management/__init__.py", line 109, in get_commands
apps = settings.INSTALLED_APPS
File "/Users/rfong/Dropbox/code/lattis_workspace/lattis_repo/venv/lib/python2. 7/site-packages/django/conf/__init__.py", line 52, in __getattr__
self._setup(name)
File "/Users/rfong/Dropbox/code/lattis_workspace/lattis_repo/venv/lib/python2. 7/site-packages/django/conf/__init__.py", line 48, in _setup
self._configure_logging()
File "/Users/rfong/Dropbox/code/lattis_workspace/lattis_repo/venv/lib/python2. 7/site-packages/django/conf/__init__.py", line 75, in _configure_logging
logging_config_func(DEFAULT_LOGGING)
File "/Users/rfong/Dropbox/code/lattis_workspace/lattis_repo/venv/lib/python2. 7/site-packages/django/utils/dictconfig.py", line 555, in dictConfig
dictConfigClass(config).configure()
File "/Users/rfong/Dropbox/code/lattis_workspace/lattis_repo/venv/lib/python2. 7/site-packages/django/utils/dictconfig.py", line 323, in configure
del logging._handlerList[:]
AttributeError: 'module' object has no attribute '_handlerList'
It seems that you installed outdated 0.4.9.6 version of logging module, presumably with pip. Correct version, shipped with python 2.7 is 0.5.1.2, and I suppose in your case might be located in /Library/Python/2.7/lib/logging. Correct version can be uploaded from python svn.
If you use pip, you always can find out which module versions are installed with
$ pip freeze
to ensure that correct versions of packages are installed, use following syntax:
$ pip install <package>==<version>
this will save you lot of pain and efforts, and almost a must on production environments.