Django_extensions failing to work with iPython notebook - django

I am using Django 1.4.5 and have just installed django-extensions, in a virtualenv. I am using Python 2.7.1. When I type:
./manage.py shell_plus --notebook
I get the error:
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/.../lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/Users/.../lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/.../lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/.../lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/Users/.../lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
return self.handle_noargs(**options)
File "/Users/.../lib/python2.7/site-packages/django_extensions/management/commands/shell_plus.py", line 140, in handle_noargs
run_notebook()
File "/Users/.../lib/python2.7/site-packages/django_extensions/management/commands/shell_plus.py", line 71, in run_notebook
from IPython.frontend.html.notebook import notebookapp
ImportError: No module named IPython.frontend.html.notebook
Without the --notebook option it works fine. Also, ipython notebook works fine too.
Can anyone suggest what might be going wrong?
thanks!

I solved this by using a new virtualenv, and making sure I had installed iPython in it, i.e:
pip install tornado
pip install pyzmq
pip install ipython
./manage.py shell_plus --notebook

In addition to what user [https://stackoverflow.com/users/905720/racing-tadpole](Racing Tadpole) said above, I also had to install jinja2.
pip install jinja2
A way to test what is missing to have django shell_plus on ipython notebook is trying to execute ipython notebook alone. This way I could detect all missing libraries, like jinja2.
ipython notebook
If this works, your chances are high that shell_plus --notebook will also work.

Related

django extensions OSError: [Errno 2] "dot.exe" not found in path

I am trying to install django-extensions to visualize my models in my Django rest project. Complete stacktrace:
(vb_env_drf) D:\Development\Bern\VB_rewrite\VB_DRF_Backend>pip install django-extensions
Collecting django-extensions
Using cached https://files.pythonhosted.org/packages/d4/b5/f141b351b49db2cb4c855cd8adbdb98cc49f3944a924ddfe51790bb46402/django_extensions-2.0.7-py2.py3-none-any.whl
Requirement already satisfied: six>=1.2 in d:\development\bern\vb_rewrite\vb_env_drf\lib\site-packages (from django-extensions) (1.11.0)
Requirement already satisfied: typing; python_version < "3.5" in d:\development\bern\vb_rewrite\vb_env_drf\lib\site-packages (from django-extensions) (3.6.4)
Installing collected packages: django-extensions
Successfully installed django-extensions-2.0.7
You are using pip version 10.0.0, however version 10.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
(vb_env_drf) D:\Development\Bern\VB_rewrite\VB_DRF_Backend>python manage.py graph_models -a -o myapp_models.png
CommandError: Neither pygraphviz nor pydotplus could be found to generate the image
(vb_env_drf) D:\Development\Bern\VB_rewrite\VB_DRF_Backend>pip install pyparsing
Collecting pyparsing
Using cached https://files.pythonhosted.org/packages/6a/8a/718fd7d3458f9fab8e67186b00abdd345b639976bc7fb3ae722e1b026a50/pyparsing-2.2.0-py2.py3-none-any.whl
Installing collected packages: pyparsing
Successfully installed pyparsing-2.2.0
You are using pip version 10.0.0, however version 10.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
(vb_env_drf) D:\Development\Bern\VB_rewrite\VB_DRF_Backend>pip install pydot
Collecting pydot
Requirement already satisfied: pyparsing>=2.1.4 in d:\development\bern\vb_rewrite\vb_env_drf\lib\site-packages (from pydot) (2.2.0)
Installing collected packages: pydot
Successfully installed pydot-1.2.4
You are using pip version 10.0.0, however version 10.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
(vb_env_drf) D:\Development\Bern\VB_rewrite\VB_DRF_Backend>python manage.py graph_models -a -o myapp_models.png
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "D:\Development\Bern\VB_rewrite\vb_env_drf\lib\site-packages\django\core\management\__init__.py", line 364, in execute_from_command_line
utility.execute()
File "D:\Development\Bern\VB_rewrite\vb_env_drf\lib\site-packages\django\core\management\__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "D:\Development\Bern\VB_rewrite\vb_env_drf\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "D:\Development\Bern\VB_rewrite\vb_env_drf\lib\site-packages\django\core\management\base.py", line 330, in execute
output = self.handle(*args, **options)
File "D:\Development\Bern\VB_rewrite\vb_env_drf\lib\site-packages\django_extensions\management\utils.py", line 59, in inner
ret = func(self, *args, **kwargs)
File "D:\Development\Bern\VB_rewrite\vb_env_drf\lib\site-packages\django_extensions\management\commands\graph_models.py", line 168, in handle
self.render_output_pydot(dotdata, **options)
File "D:\Development\Bern\VB_rewrite\vb_env_drf\lib\site-packages\django_extensions\management\commands\graph_models.py", line 230, in render_output_pydot
graph.write(output_file, format=format)
File "D:\Development\Bern\VB_rewrite\vb_env_drf\lib\site-packages\pydot.py", line 1756, in write
s = self.create(prog, format, encoding=encoding)
File "D:\Development\Bern\VB_rewrite\vb_env_drf\lib\site-packages\pydot.py", line 1867, in create
raise OSError(*args)
OSError: [Errno 2] "dot.exe" not found in path.
(vb_env_drf) D:\Development\Bern\VB_rewrite\VB_DRF_Backend>
I have added django_extensions in my settings also,
GRAPH_MODELS = {
'all_applications': True,
'group_models': True,
}
My requirements.ts looks like following:
Django==1.11.12
djangorestframework==3.8.2
django-cors-headers==2.2.0
drfdocs==0.0.11
mysql-python==1.2.5
django-rest-auth==0.9.3
django-allauth==0.35.0
nltk==3.2.5
django-extensions==2.0.7
pyparsing==2.2.0
pydot==1.2.4
I am on Windows 10. How do I resolve this error? Do I need to add anything in my Windows path?Or for Django rest I need other library (https://github.com/chibisov/drf-extensions)
dot.exe is a graphviz executable, which is not found in the search paths.
Have you installed graphviz and its dependencies?
If yes, are they in the search path of windows?

Permission error when installing Django within virtual environment

I have Django 1.10 installed within a virtualenv on my machine. Now I am creating another virtualenv (for another project) and installing Django 1.11 on it using the following command:
pip install Django
but I get a permission denied error:
Collecting Django
Using cached Django-1.11.5-py2.py3-none-any.whl
Requirement already satisfied: pytz in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages (from Django)
Installing collected packages: Django
Exception:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/commands/install.py", line 342, in run
prefix=options.prefix_path,
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/req/req_set.py", line 784, in install
**kwargs
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/req/req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/req/req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/wheel.py", line 377, in move_wheel_files
clobber(source, dest, False, fixer=fixer, filter=filter)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/wheel.py", line 323, in clobber
shutil.copyfile(srcfile, destfile)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/shutil.py", line 115, in copyfile
with open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: '/Library/Frameworks/Python.framework/Versions/3.5/bin/__pycache__/django-admin.cpython-35.pyc'
I have read multiple SO posts about this but their solutions dont seem to apply to me. Please note:
1) I have already activated the new virtualenv before running the command.
2) I did not create the new virtualenv using sudo. I just did the following to create it:
virtualenv name-of-the-new-virtualenv
What could I be missing?
When using bash, the version of python being resolved in the PATH can be seen at any time by using which python.
You can also check the location of your sourced virtualenv by viewing the VIRTUAL_ENV environment variable (e.g. echo $VIRTUAL_ENV).
In this case, the issue was that the virtualenv directory had been moved after being created, so the PATH environment variable wasn't getting populated with the virtualenv's correct bin directory upon sourcing. One solution for moving a virtualenv is to make it "relocatable", which is explained in this answer.
Virtualenvs can be activated by sourcing the activate script:
source /path/to/my/venv/bin/activate
When any virtualenv has been sourced, it can be deactivated by using the deactivate function:
deactivate

pip install django on go daddy shows error

When i run command pip install django, on go daddy it gives me the following error:
I tried to copy django packages manually into the site-packages of go daddy. I copied it from my local machine. I removed all of them.(I don't know if there is something remaining or not. But i have checked it again) Can you please help with this?
DEPRECATION: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of pip will drop support for Python 2.6
Collecting django
Using cached Django-1.11.3-py2.py3-none-any.whl
Requirement already satisfied: pytz in /usr/lib/python2.6/site-packages (from django)
Installing collected packages: django
Exception:
Traceback (most recent call last):
File "/home/lmtech123/.local/lib/python2.6/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/home/lmtech123/.local/lib/python2.6/site-packages/pip/commands/install.py", line 342, in run
prefix=options.prefix_path,
File "/home/lmtech123/.local/lib/python2.6/site-packages/pip/req/req_set.py", line 784, in install
**kwargs
File "/home/lmtech123/.local/lib/python2.6/site-packages/pip/req/req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/home/lmtech123/.local/lib/python2.6/site-packages/pip/req/req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "/home/lmtech123/.local/lib/python2.6/site-packages/pip/wheel.py", line 345, in move_wheel_files
clobber(source, lib_dir, True)
File "/home/lmtech123/.local/lib/python2.6/site-packages/pip/wheel.py", line 316, in clobber
ensure_dir(destdir)
File "/home/lmtech123/.local/lib/python2.6/site-packages/pip/utils/__init__.py", line 83, in ensure_dir
os.makedirs(path)
File "/usr/lib64/python2.6/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 30] Read-only file system: '/usr/lib64/python2.6/site-packages/Django-1.11.3.dist-info'
The easy way is update to new version of Python3
sudo apt-get install python3

Running django-admin tutorial erros: no module named django

I just started to try and install/run Django on my cmd prompt and faced this issue although environment variables are set up for Django.
Besides getting a solution, can someone help me understand the root cause of the error below?
C:\Python>django-admin startproject test
Traceback (most recent call last):
File "C:\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\windows\syswow64\scripts\django-admin.exe\__main__.py", line 5, in <module>
ModuleNotFoundError: No module named 'django'
In python based project it is always good to create Virtual Environment and then run your django program .
pip install virtualenvwrapper-win
mkvirtualenv test
workon test
this will activate your virtual environment
Now install django
pip install django
After django installation complets
run
django-admin --version
Hope this helps.
On windows, go where you want to create your project, and call from there the django-admin.exe:
path\to\django-admin.exe startproject project_name
Its not a clean solution but worked for me.

Installing aws cli

I am getting this message when I try to install aws. Anyone have any ideas of what's going on?
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip/basecommand.py", line 209, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip/commands/install.py", line 317, in run
prefix=options.prefix_path,
File "/Library/Python/2.7/site-packages/pip/req/req_set.py", line 725, in install
requirement.uninstall(auto_confirm=True)
File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 756, in uninstall
paths_to_remove.remove(auto_confirm)
File "/Library/Python/2.7/site-packages/pip/req/req_uninstall.py", line 115, in remove
renames(path, new_path)
File "/Library/Python/2.7/site-packages/pip/utils/__init__.py", line 266, in renames
shutil.move(old, new)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, in move
copy2(src, real_dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2
copystat(src, dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, in copystat
os.chflags(dst, st.st_flags)
OSError: [Errno 1] Operation not permitted: '/tmp/pip-TIuiKe-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'
The command I'm using is pip install awscli
The problem is about permisson. The installer are trying to write in a folder that doesnt have permission.
try sudo pip install awscli
It looks like it is trying to uninstall six-1.4.1. I had the same issue. Telling pip to ignore installed package should work.
sudo pip install --ignore-installed awscli
sudo pip install --upgrade --user awscli
--upgrade : tells pip to upgrade any requirements that are already installed