Difference running python in PyCharm and in terminal - python-2.7

I'm wondering what is the difference when I run a python program from PyCharm or from the command line.
Actually I'm using a library called wand-py (ImageMagick binding).
If I run my program from the command line it works.
Though if I use PyCharm Run or debug it doesn't and I get the following traceback.
/Users/alexisbenoist/Documents/python/papyrus/env/bin/python "/Applications/PyCharm CE.app/helpers/pydev/pydevd.py" --multiproc --client 127.0.0.1 --port 58993 --file /Users/alexisbenoist/Documents/python/papyrus/tets.py
Connected to pydev debugger (build 135.973)
pydev debugger: process 73166 is connecting
Traceback (most recent call last):
File "/Applications/PyCharm CE.app/helpers/pydev/pydevd.py", line 1733, in <module>
debugger.run(setup['file'], None, None)
File "/Applications/PyCharm CE.app/helpers/pydev/pydevd.py", line 1226, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "/Users/alexisbenoist/Documents/python/papyrus/tets.py", line 23, in <module>
blob = image_to_blob(PATH)
File "/Users/alexisbenoist/Documents/python/papyrus/tets.py", line 12, in image_to_blob
pdf.alpha_channel = False
File "/Users/alexisbenoist/Documents/python/papyrus/env/lib/python2.7/site-packages/wand/image.py", line 419, in wrapped
result = function(self, *args, **kwargs)
File "/Users/alexisbenoist/Documents/python/papyrus/env/lib/python2.7/site-packages/wand/image.py", line 992, in alpha_channel
self.raise_exception()
File "/Users/alexisbenoist/Documents/python/papyrus/env/lib/python2.7/site-packages/wand/resource.py", line 218, in raise_exception
raise e
wand.exceptions.WandError: wand contains no images `MagickWand-1' # error/magick-image.c/MagickSetImageAlphaChannel/9504
I'm using the same virtual env in the terminal and PyCharm.
Do you guys know what could cause the problem?
Thanks,
Alexis.

Related

Can't connect superset to dremio

I am running apache-superset using docker-compose by following the instructions here (https://superset.apache.org/docs/installation/installing-superset-using-docker-compose/) using docker-compose-non-dev.yml.
I have also added sqlalchemy-dremio to superset/docker/requirements-local.txt, in order to add dremio support as mentioned here (https://superset.apache.org/docs/databases/docker-add-drivers)
For dremio, I have a seperate container running on dremio/dremio-oss image using
docker run -p 9047:9047 -p 31010:31010 -p 45678:45678 -p 32010:32010 dremio/dremio-oss
and then made an account in dremio using the web interface at localhost:9047
But when I try to add dremio as a database in superset I get the following errors
on pressing test connection I get the following error
The connection string I'm using is
dremio+flight://dremio:dremio123#host.docker.internal:32010/dremio;SSL=0
At first I thought it might be a network error or an error in dremio, but I can connect to dremio using the python script here https://github.com/dremio-hub/arrow-flight-client-examples/blob/main/python/example.py
python example.py -host host.docker.internal -query 'SELECT 1'
This script runs successfully from both outside the container from host_os using localhost and from inside the superset_app container using host.docker.internal as host. Therefore I don't think its a network configuration problem, also this confirms that the sqlalchemy-dremio package was installed properly inside the superset containers.
Here is the docker logs for this error from superset_app container
2022-09-30 16:34:09,635:WARNING:superset.views.base:SupersetErrorsException
Traceback (most recent call last):
File "/app/superset/databases/commands/test_connection.py", line 123, in run
raise DBAPIError(None, None, None)
sqlalchemy.exc.DBAPIError: (builtins.NoneType) None
(Background on this error at: https://sqlalche.me/e/14/dbapi)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1516, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1502, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "/usr/local/lib/python3.8/site-packages/flask_appbuilder/security/decorators.py", line 89, in wraps
return f(self, *args, **kwargs)
File "/app/superset/views/base_api.py", line 114, in wraps
raise ex
File "/app/superset/views/base_api.py", line 111, in wraps
duration, response = time_function(f, self, *args, **kwargs)
File "/app/superset/utils/core.py", line 1572, in time_function
response = func(*args, **kwargs)
File "/app/superset/utils/log.py", line 244, in wrapper
value = f(*args, **kwargs)
File "/app/superset/views/base_api.py", line 84, in wraps
return f(self, *args, **kwargs)
File "/app/superset/databases/api.py", line 708, in test_connection
TestConnectionDatabaseCommand(item).run()
File "/app/superset/databases/commands/test_connection.py", line 148, in run
raise DatabaseTestConnectionFailedError(errors) from ex
superset.databases.commands.exceptions.DatabaseTestConnectionFailedError: [SupersetError(message='(builtins.NoneType) None\n(Background on this error at: https://sqlalche.me/e/14/dbapi)', error_type=<SupersetErrorType.GENERIC_DB_ENGINE_ERROR: 'GENERIC_DB_ENGINE_ERROR'>, level=<ErrorLevel.ERROR: 'error'>, extra={'engine_name': 'Dremio', 'issue_codes': [{'code': 1002, 'message': 'Issue 1002 - The database returned an unexpected error.'}]})]
***************
['UID=dremio', 'PWD=dremio123', 'HOST=host.docker.internal', 'PORT=32010', 'Schema=dremio', 'SSL=0']
***************
Ensure you are installing the latest version of sqlalchemy_dremio. You may need to install from source as setup.py wasn't updated accordingly (around time of writing). You will also need to add some SQLAlchemy base functions to sqlalchemy_dremio. Have a look at the following issue: https://github.com/narendrans/sqlalchemy_dremio/issues/20

Failed Manage.py runserver command

I'm a beginner in web development. I'm using pycharm and django 2.1 framework
I installed django using ('py -m pip install django==2.1') and it is done.
I started myweb project using ('py -m django-admin startproject myweb .') and it also done
but when I try ('manage.py runserver') command, this is the result:
(venv) C:\Users\مرحبا\PycharmProjects\Myweb>manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
March 27, 2020 - 20:08:58
Django version 3.0.4, using settings 'myweb.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Exception in thread <bound method Thread.name of <Thread(django-main-thread,
started
daemon 5152)>>:
Traceback (most recent call last):
File "C:\Users\مرحبا\AppData\Local\Programs\lib\threading.py", line 917, in
_bootstrap_inner
self.run()
File "C:\Users\مرحبا\AppData\Local\Programs\lib\threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\مرحبا\AppData\Local\Programs\lib\site-
packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\مرحبا\AppData\Local\Programs\lib\site-
packages\django\core\management\commands\runserver.py", line 139, in inner_run
ipv6=self.use_ipv6, threading=threading, server_cls=self.server_cls)
File "C:\Users\مرحبا\AppData\Local\Programs\lib\site-
packages\django\core\servers\basehttp.py", line 206, in run
httpd = httpd_cls(server_address, WSGIRequestHandler, ipv6=ipv6)
File "C:\Users\مرحبا\AppData\Local\Programs\lib\site-
packages\django\core\servers\basehttp.py", line 67, in __init__
super().__init__(*args, **kwargs)
File "C:\Users\مرحبا\AppData\Local\Programs\lib\socketserver.py", line 449, in
__init__
self.server_bind()
File "C:\Users\مرحبا\AppData\Local\Programs\lib\wsgiref\simple_server.py", line
50,
in server_bind
HTTPServer.server_bind(self)
File "C:\Users\مرحبا\AppData\Local\Programs\lib\http\server.py", line 139, in
server_bind
self.server_name = socket.getfqdn(host)
File "C:\Users\مرحبا\AppData\Local\Programs\lib\socket.py", line 680, in getfqdn
aliases.insert(0, hostname)
AttributeError: 'str' object has no attribute 'insert'
Could you help me please?
In the last line of the error it says
aliases.insert(0, hostname) AttributeError: 'str' object has no attribute 'insert'
Your Aliases variables is a string, not a list, so you can't .insert() to it, as that functionality doesn't exist.
You need to make sure Aliases is a list in your code.

Error while Running Python manage.py runserver comman [duplicate]

This question already has answers here:
Unicodedecodeerror with runserver
(3 answers)
Closed 2 years ago.
I have started learning django this was my first tutorial.
First i ran django-admin startproject
This command works according to tutorial but when I run this command
python manage.py runserver
Following Error Occurs but not in tutorial video
*Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
September 27, 2019 - 18:01:04
Django version 2.2.5, using settings 'first.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Exception in thread django-main-thread:
Traceback (most recent call last): File
"C:\Users\MuBasHer\AppData\Local\Programs\Python\Python37\lib\threading.py",
line 917, in _bootstrap_inner self.run() File
"C:\Users\MuBasHer\AppData\Local\Programs\Python\Python37\lib\threading.py",
line 865, in run
self._target(*self._args, **self._kwargs) File "C:\Users\MuBasHer\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\autoreload.py",
line 54, in wrapper
fn(*args, **kwargs) File "C:\Users\MuBasHer\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\commands\runserver.py",
line 139, in inner_run
ipv6=self.use_ipv6, threading=threading, server_cls=self.server_cls) File
"C:\Users\MuBasHer\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\servers\basehttp.py",
line 203, in run
httpd = httpd_cls(server_address, WSGIRequestHandler, ipv6=ipv6) File
"C:\Users\MuBasHer\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\servers\basehttp.py",
line 67, in init
super().init(*args, **kwargs) File "C:\Users\MuBasHer\AppData\Local\Programs\Python\Python37\lib\socketserver.py",
line 449, in init
self.server_bind() File "C:\Users\MuBasHer\AppData\Local\Programs\Python\Python37\lib\wsgiref\simple_server.py",
line 50, in server_bind
HTTPServer.server_bind(self) File "C:\Users\MuBasHer\AppData\Local\Programs\Python\Python37\lib\http\server.py",
line 139, in server_bind
self.server_name = socket.getfqdn(host) File "C:\Users\MuBasHer\AppData\Local\Programs\Python\Python37\lib\socket.py",
line 676, in getfqdn
hostname, aliases, ipaddrs = gethostbyaddr(name) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xae in position
6: invalid start byte *
You need to change hostname in Windows to remove any not UTF-8 characters.
first of all, I assume you are using the windows command-line tool as your shell.
If so, then run the command-line tool as administrator and
cd into your project directory, switch into your working(virtual environment),
then run the python manage.py runserver command again.
With these few steps you can startup your development server.
thanks

Trying to deploy on pythonanywhere and not working

I've downloaded the pythonanywhere installation tool and am trying to deploy with the following line:
pa_autoconfigure_django.py <https://github.com/myusername/myproject.git>
Then, I get this a key error. My project runs on local.
File "/projects/hosproject/venv/lib/python3.7/site-packages/pythonanywhere/project.py", line 16, in __init__
self.virtualenv = Virtualenv(self.domain, self.python_version)
File "/projects/hosproject/venv/lib/python3.7/site-packages/pythonanywhere/virtualenvs.py", line 12, in __init__
self.path = Path(os.environ["WORKON_HOME"]) / domain
File "/projects/hosproject/venv/bin/../lib/python3.7/os.py", line 678, in __getitem__
raise KeyError(key) from None
KeyError: 'WORKON_HOME'
Need some help to debug this and try to deploy again. If it helps, I'm new to Django and following this tutorial: https://tutorial.djangogirls.org/en/deploy/.
As noted by Giles:
It looks like you might be running the PythonAnywhere tools from a terminal on your own machine -- you should run it in a bash console on PythonAnywhere -- you can start one from the "Consoles" page. (emphasis mine)
However I only got to this KeyError: WORKON_HOME after running several commands I shouldn't have (at least it'll make clean up easier):
$ pip3 install --user pythonanywhere
$ pa_autoconfigure_django.py --python=3.7 git#github.com:pzrq/djangogirls-tutorial-blog.git
-bash: pa_autoconfigure_django.py: command not found
$ find / -name "pa_autoconfigure_django.py"
$ /Users/pzrq/Library/Python/3.7/bin/pa_autoconfigure_django.py --python=3.7 git#github.com:pzrq/djangogirls-tutorial-blog.git
Traceback (most recent call last):
File "/Users/pzrq/Library/Python/3.7/bin/pa_autoconfigure_django.py", line 19, in <module>
from docopt import docopt
ModuleNotFoundError: No module named 'docopt'
$ pip install docopt
...
$ /Users/pzrq/Library/Python/3.7/bin/pa_autoconfigure_django.py --python=3.7 git#github.com:pzrq/djangogirls-tutorial-blog.git
...
ModuleNotFoundError: No module named 'pythonanywhere'
$ pip install pythonanywhere
...
$ /Users/pzrq/Library/Python/3.7/bin/pa_autoconfigure_django.py --python=3.7 git#github.com:pzrq/djangogirls-tutorial-blog.git
Traceback (most recent call last):
File "/Users/pzrq/Library/Python/3.7/bin/pa_autoconfigure_django.py", line 52, in <module>
main(arguments['<git-repo-url>'], arguments['--domain'], arguments['--python'], nuke=arguments.get('--nuke'))
File "/Users/pzrq/Library/Python/3.7/bin/pa_autoconfigure_django.py", line 33, in main
project = DjangoProject(domain, python_version)
File "/Users/pzrq/Projects/djangogirls/myvenv/lib/python3.7/site-packages/pythonanywhere/project.py", line 16, in __init__
self.virtualenv = Virtualenv(self.domain, self.python_version)
File "/Users/pzrq/Projects/djangogirls/myvenv/lib/python3.7/site-packages/pythonanywhere/virtualenvs.py", line 12, in __init__
self.path = Path(os.environ["WORKON_HOME"]) / domain
File "/usr/local/bin/../Cellar/python/3.7.3/bin/../Frameworks/Python.framework/Versions/3.7/lib/python3.7/os.py", line 678, in __getitem__
raise KeyError(key) from None
KeyError: 'WORKON_HOME'

portia (scrapy/slybot) errors on windows

i installed portia and got it to work i annotated some websites (looks really good)
but when i try to run the spiders i get some errors and nothing gets crawled
im running python 2.7.6 on win 7
C:\Python27\Scripts>python portiacrawl C:\portia\slyd\data\projects\new_project
Traceback (most recent call last):
File "portiacrawl", line 7, in <module>
execfile(__file__)
File "C:\portia\slybot\bin\portiacrawl", line 56, in <module>
main()
File "C:\portia\slybot\bin\portiacrawl", line 54, in main
subprocess.call(command_spec)
File "C:\Python27\lib\subprocess.py", line 522, in call
return Popen(*popenargs, **kwargs).wait()
File "C:\Python27\lib\subprocess.py", line 709, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 957, in _execute_child
startupinfo)
WindowsError: [Error 2] O sistema nÒo conseguiu localizar o ficheiro especificado
I am troubleshooting portia on Windows 8.1 and encountered the same error, exactly.
Try running 'python portiacrawl' by itself to determine if there is a subsequent menu. You should be able to see Help info on 'portiacrawl'. I suspect that you need to name the [spider] & [options] as well as change the terminal directory to see the output from the crawler. I suggest trying the following but rename [spider] to actual name of your spider w/o brackets:
Enter into terminal: C:\portia\slyd\data\projects <------Change to proper directory in cmd
Make sure you are in the terminal directory "C:\portia\slyd\data\projects"
The Cmd propmpt should look like: C:\portia\slyd\data\projects> <----waiting for portia initiation.
Enter into terminal:
python portiacrawl C:\portia\slyd\data\projects\new_project [spider] -t csv -o test.csv; or,
python portiacrawl [spider] -t csv -o test.csv
Report back. I am curious as to the terminal response. Did it initiate portiacrawl & return "access is denied."