I have Python installed on the Mac. If I run python -V it outputs 3.7.2
If I run the following:
virtualenv venv
source venv/bin/activate
python -V
I see 3.7.2.
If I try to run nose I get this error:
$ nosetests -s -v config_test.test_config:TestConfiguration
Failure: ModuleNotFoundError (No module named 'boto3') ... ERROR
======================================================================
ERROR: Failure: ModuleNotFoundError (No module named 'boto3')
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/nose/failure.py", line 39, in runTest
raise self.exc_val.with_traceback(self.tb)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/nose/loader.py", line 418, in loadTestsFromName
addr.filename, addr.module)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/nose/importer.py", line 47, in importFromPath
return self.importFromDir(dir_path, fqname)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/nose/importer.py", line 94, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/imp.py", line 234, in load_module
return load_source(name, filename, file)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/imp.py", line 172, in load_source
module = _load(spec)
File "<frozen importlib._bootstrap>", line 675, in _load
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "/Users/me/git/sdk-python-config/config_test/config_sdk.py", line 4, in <module>
import boto3
ModuleNotFoundError: No module named 'boto3'
----------------------------------------------------------------------
Ran 1 test in 0.001s
FAILED (errors=1)
I'm immediately concerned with the 3.6 references.
If I then run pip install boto3 I can see the package when I run pip list however I get the same error as above when I try running my applicaiton again.
I've tried pyenv global 3.7.2 and pyenv local 3.7.2 but neither makes any difference.
Can anybody suggest what the problem might be?
nose wasn't installed in the venv. After I installed it with pip install nose I had to deactivate the venv and reactivate it.
Related
I have a .py script that uses torchaudio (without GPU) to process some sound in Windows. To distribute it, I've used pyinstaller to turn it into a .exe. You can reproduce the issue with this simple script:
import torchaudio
import time
if __name__ == '__main__':
t = torchaudio.transforms
time.sleep(3)
print("Success")
This script correctly runs from a python console python test.py but I want to create a test.exe that works in Windows (without having python installed). I create test.exe by using pyinstaller: pyinstaller test.py. This creates a build/test folder with all the required dependencies (around 1GB). test.exe is located inside that folder but when I double click on it, it fails with the following error:
Traceback (most recent call last):
File "torch\_ops.py", line 501, in __getattr__
op, overload_names = torch._C._jit_get_operation(qualified_op_name)
RuntimeError: No such operator torchaudio::cuda_version
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "test.py", line 1, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "torchaudio\__init__.py", line 1, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "torchaudio\_extension.py", line 136, in <module>
File "torchaudio\_extension.py", line 121, in _check_cuda_version
File "torch\_ops.py", line 505, in __getattr__
raise AttributeError(
AttributeError: '_OpNamespace' 'torchaudio' object has no attribute 'cuda_version'
[11648] Failed to execute script 'test' due to unhandled exception!
The environment uses:
python==3.9.15
torch==1.13.0
six==1.15.0
numpy==1.22.4
scipy==1.6.0
sounddevice==0.4.5
torchaudio==0.13.0
pyinstaller==5.6.2
Note: I tried the same installing torch with cuda ending up with the same error and a build 4 times bigger.
I was able to make the script work. Here are the steps I took to get it to run.
Create a new empty directory and pasted your script in as main.py
py -m venv venv && venv\scripts\activate && py -m pip install --upgrade pip pyinstaller
pip install torchaudio==0.13.0 torch==1.13.0 numpy=1.22.4 sounddevice==0.4.5 six==1.15.0 scipy
pyinstaller -F main.py
Go into venv\Lib\site-packages and copy the entire torchaudio folder and paste it into the top level directory alongside venv and main.py
In main.spec set datas=[('./torchaudio','./torchaudio')]
pyinstaller main.spec
And after compiling the executable runs... it still gives off a few warnings, but it runs and prints the success message.
I am a new python programmer and was testing out pyttsx3, I am trying to use nsss. However when I run the following code
import pyttsx3
engine=pyttsx3.init('nsss')
engine.say ("Top of the morning")
# angine=pyttsx3.init()
# angine.say("Why hello there")
# angine.runAndWait()
It says error Foundation module not found, so I installed it with pip install foundation. This installs foundation and django version 1.10.8 which to my understanding is not compatible with python v 3.9. But when I install Django version 3.1.7, that version is not compatible with Foundation.
The error logs are below
C:\Users\Ahmed_Abdelmuniem\AppData\Local\Programs\Python\Python39\python.exe "C:/Users/Ahmed_Abdelmuniem/PycharmProjects/AI Engine/main.py"
Traceback (most recent call last):
File "C:\Users\Ahmed_Abdelmuniem\AppData\Local\Programs\Python\Python39\lib\site-packages\pyttsx3\__init__.py", line 20, in init
eng = _activeEngines[driverName]
File "C:\Users\Ahmed_Abdelmuniem\AppData\Local\Programs\Python\Python39\lib\weakref.py", line 134, in __getitem__
o = self.data[key]()
KeyError: 'nsss'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Ahmed_Abdelmuniem\PycharmProjects\AI Engine\main.py", line 3, in <module>
engine=pyttsx3.init('nsss')
File "C:\Users\Ahmed_Abdelmuniem\AppData\Local\Programs\Python\Python39\lib\site-packages\pyttsx3\__init__.py", line 22, in init
eng = Engine(driverName, debug)
File "C:\Users\Ahmed_Abdelmuniem\AppData\Local\Programs\Python\Python39\lib\site-packages\pyttsx3\engine.py", line 30, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "C:\Users\Ahmed_Abdelmuniem\AppData\Local\Programs\Python\Python39\lib\site-packages\pyttsx3\driver.py", line 50, in __init__
self._module = importlib.import_module(name)
File "C:\Users\Ahmed_Abdelmuniem\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "C:\Users\Ahmed_Abdelmuniem\AppData\Local\Programs\Python\Python39\lib\site-packages\pyttsx3\drivers\nsss.py", line 2, in <module>
from Foundation import *
ModuleNotFoundError: No module named 'Foundation'
Process finished with exit code 1
install the necessary libraries and run in separate virtual environment
sudo apt-get install python-espeak
sudo apt-get update && sudo apt-get install espeak
using python3.9 with virtual environment,
python3.9 -m venv env
source env/bin/activate
pip install pyttsx3
now running the below demo code should work.
import pyttsx3
engine = pyttsx3.init()
engine.say("I will speak this text")
engine.runAndWait()
I am trying to install pgadmin4 on ubuntu vps server but i am unable to install . I am getting this error
postgres version 12.2
ubuntu version 18.04
unable to figure out this error , any help would be appreciated tried everything but didnot worked
Setting up pgadmin4-apache2 (4.18-1.pgdg18.04+1) ...
apache2_invoke pgadmin4: already enabled
Traceback (most recent call last):
File "setup.py", line 413, in <module>
setup_db()
File "setup.py", line 347, in setup_db
app = create_app()
File "/usr/share/pgadmin4/web/pgadmin/__init__.py", line 400, in create_app
driver.init_app(app)
File "/usr/share/pgadmin4/web/pgadmin/utils/driver/__init__.py", line 40, in init_app
DriverRegistry.load_drivers()
File "/usr/share/pgadmin4/web/pgadmin/utils/driver/registry.py", line 88, in load_drivers
module = import_module(module_name)
File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/usr/share/pgadmin4/web/pgadmin/utils/driver/psycopg2/__init__.py", line 28, in <module>
from .server_manager import ServerManager
File "/usr/share/pgadmin4/web/pgadmin/utils/driver/psycopg2/server_manager.py", line 30, in <module>
from sshtunnel import SSHTunnelForwarder, BaseSSHTunnelForwarderError
File "/usr/lib/python3/dist-packages/sshtunnel.py", line 25, in <module>
import paramiko
File "/usr/lib/python3/dist-packages/paramiko/__init__.py", line 30, in <module>
from paramiko.transport import SecurityOptions, Transport
File "/usr/lib/python3/dist-packages/paramiko/transport.py", line 66, in <module>
from paramiko.sftp_client import SFTPClient
File "/usr/lib/python3/dist-packages/paramiko/sftp_client.py", line 41, in <module>
from paramiko.sftp_file import SFTPFile
File "/usr/lib/python3/dist-packages/paramiko/sftp_file.py", line 66
self._close(async=True)
^
SyntaxError: invalid syntax
dpkg: error processing package pgadmin4-apache2 (--configure):
installed pgadmin4-apache2 package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
pgadmin4-apache2
E: Sub-process /usr/bin/dpkg returned an error code (1)
Solution for me was explicitly install package python3-paramiko:
apt-get install python3-paramiko
Resulted in:
Preparing to unpack .../python3-paramiko_2.6.0-2_all.deb ...
Unpacking python3-paramiko (2.6.0-2) over (2.0.0-1ubuntu1.2) ...
Setting up python3-bcrypt (3.1.7-2ubuntu1) ...
Setting up python3-cryptography (2.8-3ubuntu0.1) ...
Setting up pgadmin4-apache2 (4.25-1.pgdg20.04+1) ...
pgAdmin 4 - Application Initialisation
======================================
Setting up python3-nacl (1.3.0-5) ...
Setting up python3-paramiko (2.6.0-2) ...
Happened during release upgrade from 18.04 to 20.04. Error traceback was the same.
from pgadmin website:
Setup the repository
Install the public key for the repository (if not done previously):
sudo curl https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo apt-key add
Create the repository configuration file:
sudo sh -c 'echo "deb https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/$(lsb_release -cs) pgadmin4 main" > /etc/apt/sources.list.d/pgadmin4.list && apt update'
Install pgAdmin
Install for both desktop and web modes:
sudo apt install pgadmin4
Install for desktop mode only:
sudo apt install pgadmin4-desktop
Install for web mode only:
sudo apt install pgadmin4-web
Configure the webserver, if you installed pgadmin4-web:
sudo /usr/pgadmin4/bin/setup-web.sh
As printed in log issue is in
File "/usr/lib/python3/dist-packages/paramiko/sftp_file.py", line 66
self._close(async=True)
The problem seems to be with the name choosen for the variable async set to True in the above example.
async is also a python command, so I suppose Python interpret async as the python command not a variable.
I renamed all async variable to aasync in file "/usr/lib/python3/dist-packages/paramiko/sftp_file.py" and then try to install python3-paramiko.
I have no error anymore.
I am trying to install readthedocs in local system (Ubuntu 14.04 ) in python3 virtual env from the instructions given in this link
When I ran pip3 install -r requirements.txt , I got an error for Distutils2 . I removed that dependency as the distutils2 is no longer supported and assumed setuptools would suffice.
Running this command python manage.py migrate gave the below error :
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_from_command_line(sys.argv)
File "/home/username/read_the_docs_env/lib/python3.4/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/home/username/read_the_docs_env/lib/python3.4/site-packages/django/core/management/__init__.py", line 312, in execute
django.setup()
File "/home/username/read_the_docs_env/lib/python3.4/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/username/read_the_docs_env/lib/python3.4/site-packages/django/apps/registry.py", line 115, in populate
app_config.ready()
File "/home/username/read_the_docs_env/lib/python3.4/site-packages/django/contrib/admin/apps.py", line 22, in ready
self.module.autodiscover()
File "/home/username/read_the_docs_env/lib/python3.4/site-packages/django/contrib/admin/__init__.py", line 24, in autodiscover
autodiscover_modules('admin', register_to=site)
File "/home/username/read_the_docs_env/lib/python3.4/site-packages/django/utils/module_loading.py", line 74, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "/home/username/read_the_docs_env/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 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/home/username/Desktop/CurrentProjects/read_the_docs/checkouts/readthedocs.org/readthedocs/core/admin.py", line 10, in <module>
from readthedocs.core.views import SendEmailView
File "/home/username/Desktop/CurrentProjects/read_the_docs/checkouts/readthedocs.org/readthedocs/core/views/__init__.py", line 26, in <module>
from readthedocs.projects.tasks import remove_dir
File "/home/username/Desktop/CurrentProjects/read_the_docs/checkouts/readthedocs.org/readthedocs/projects/tasks.py", line 493
print "Sync Versions Exception: %s" % e.message
^
SyntaxError: Missing parentheses in call to 'print'
I understand from the above stacktrace that the code is in python2 and so print statement is different in python3 .
Does this mean that I have to install readthedocs in python2 virtualenv ?
Can't we host the docs of python3 projects in readthedocs in-house server ?
The read the docs code does not support Python 3 yet. The installation instructions explicitly say to use Python 2.7:
First, obtain Python 2.7 and virtualenv
However, it should still be possible to use your read the docs installation to host docs for Python 3 projects, since the instructions then say:
If you plan to import Python 3 project to your RTD then you’ll need to install Python 3 with virtualenv in your system as well.
I'm running django using a virtualenv. For some reason, django calls httplib2 in /usr/share/qgis/python/httplib2... where there's a syntax error for some reason.
This never happened before I installed the qgis library from arch's AUR.
I don't understand why is it calling the library that's in qgis? I have this same library in the virtualenv and also on the file system (installed after the error popped-up):
[root#arch http]# pacman -Ql | grep httplib2
...
python-httplib2 /usr/lib/python3.4/site-packages/httplib2/
...
This is information abuot my virtualenv:
(app)[jenia#arch merging_map_]$ python --version
Python 3.4.1
(app)[jenia#arch merging_map_]$ pip freeze
Django==1.6.5
Pillow==2.5.1
django-simple-captcha==0.4.2
gunicorn==18.0
httplib2==0.9 <-------------- I installed this after finding the error.
ipython==2.1.0
oauthlib==0.6.3
psycopg2==2.5.3
python-social-auth==0.1.26
python3-openid==3.0.4
requests==2.3.0
requests-oauthlib==0.3.1
six==1.7.3
Here is the trace back. Its a little long, i think the most interesting is the last lines (the top of the stack). It says that that django tried to use a library in /usr/share/qgis...
trace back:
Internal Server Error: /login
Traceback (most recent call last):
File "/srv/http/merging_map_/app/lib/python3.4/site-packages/django/core/handlers/base.py", line 112, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/srv/http/merging_map_/app/zones/views.py", line 185, in my_login
user = authenticate(username=form.cleaned_data['username'], password=form.cleaned_data['password'])
File "/srv/http/merging_map_/app/lib/python3.4/site-packages/django/contrib/auth/__init__.py", line 47, in authenticate
for backend in get_backends():
File "/srv/http/merging_map_/app/lib/python3.4/site-packages/django/contrib/auth/__init__.py", line 22, in get_backends
backends.append(load_backend(backend_path))
File "/srv/http/merging_map_/app/lib/python3.4/site-packages/django/contrib/auth/__init__.py", line 16, in load_backend
return import_by_path(path)()
File "/srv/http/merging_map_/app/lib/python3.4/site-packages/django/utils/module_loading.py", line 21, in import_by_path
module = import_module(module_path)
File "/srv/http/merging_map_/app/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 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/srv/http/merging_map_/app/lib/python3.4/site-packages/social/backends/google.py", line 7, in <module>
from social.backends.open_id import OpenIdAuth
File "/srv/http/merging_map_/app/lib/python3.4/site-packages/social/backends/open_id.py", line 1, in <module>
from openid.consumer.consumer import Consumer, SUCCESS, CANCEL, FAILURE
File "/srv/http/merging_map_/app/lib/python3.4/site-packages/openid/consumer/consumer.py", line 194, in <module>
from openid import fetchers
File "/srv/http/merging_map_/app/lib/python3.4/site-packages/openid/fetchers.py", line 26, in <module>
import httplib2
File "/usr/share/qgis/python/httplib2/__init__.py", line 911
print "connect: (%s, %s) ************" % (self.host, self.port)
SyntaxError: invalid syntax
/srv/http/merging_map_/app/lib/python3.4/site.py:429: DeprecationWarning: 'U' mode is deprecated
fp = open(filename, "rU")
So how do I fix it? How do I make python execute the httplib2 that's in the virtualenv?
Thanks in advance for your time and kind help.
Jenia.
EDIT 1: system path from the virtualenv:
['', '/srv/http/merging_map_',
'/usr/share/qgis/python', <----------------------- how did this get here?!!!
'/srv/http/merging_map_/app/lib/python34.zip',
'/srv/http/merging_map_/app/lib/python3.4',
'/srv/http/merging_map_/app/lib/python3.4/plat-linux',
'/srv/http/merging_map_/app/lib/python3.4/lib-dynload',
'/usr/lib64/python3.4', '/usr/lib/python3.4',
'/usr/lib/python3.4/plat-linux',
'/srv/http/merging_map_/app/lib/python3.4/site-packages']
How in the world did the qgis folder get into the virtualenv exec paths i dont know. please tell me how to get it out!! and how to replace it with the correct python path.
So it seems that the problem is that library is in PYTHONPATH. You can remove it just doing
$ unset PYTHONPATH
$ source /path/to/venv/bin/activate
Now regarding how it got there: probably you installed something (QGIS) that add it there. You can try to find it where it is defined and remove it
$ grep -r "PYTHONPATH" /etc
Also you should check in your .bashrc and .profile files in your home folder. Of course if you remove that entry from python path, the software that needs it may stop working...