I'll try to explain this, hopefully it makes sense.
I had installed a virtual env a while ago in the directory: desktop/project_website/test_project/env and activate it to do some websites.
I also pip installed scrapy on the desktop/project_website/test_project/env/Scripts dir
The problem is that whenever I use the command prompt to run scrapy I need to be in this specific directory, so all the files that scrapy creates are made in there, not in the directory where my project is (that is desktop/project_website/Scrapy)
I already tried setting the path of where scrapy was installed into my project directory:
(Test_Project) C:\Users\A\Desktop\Project_Website\Scrapy>path
PATH=%path%;C:\Users\A\Desktop\Project_Website\Test_Project\env\Scripts
And getting this error:
(Test_Project) C:\Users\A\Desktop\Project_Website\Scrapy>scrapy
Traceback (most recent call last):
File "C:\Python\Python35\Lib\runpy.py", line 184, in _run_module_as_main
"__main__", mod_spec)
File "C:\Python\Python35\Lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\A\Desktop\Project_Website\Test_Project\env\Scripts\scrapy.exe\__main__.py", line 9, in <module>
File "c:\users\a\desktop\project_website\test_project\env\lib\site-packages\scrapy\cmdline.py", line 108, in execute
settings = get_project_settings()
File "c:\users\a\desktop\project_website\test_project\env\lib\site-packages\scrapy\utils\project.py", line 68, in get_project_settings
settings.setmodule(settings_module_path, priority='project')
File "c:\users\a\desktop\project_website\test_project\env\lib\site-packages\scrapy\settings\__init__.py", line 292, in setmodule
module = import_module(module)
File "c:\users\a\desktop\project_website\test_project\env\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ImportError: No module named 'quotes.settings'; 'quotes' is not a package
So, in short anyone know what can I do to run scrapy in my project dir? Thanks.
UPDATE - SOLVED:
Instead of using the to virtual env pathC:\Users\A\Desktop\Project_Website\Test_Project\env\Scripts I set it to where I installed scrapy on my PC c:\python\python35\scripts and it's working now.
By default, the python interpreter that occurs first in the paths will be used. You can specifically mention which interpreter to use. Something like this:
$ path_to_dir\env\bin\python runpy.py
Related
I uses PyCharm's terminal for the action below.
I was unable to install packages using pip. If I tried to install, it raises a error.
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\~\PycharmProjects\pythonProject\venv\Scripts\pip.exe\__main__.py", line 7, in <module>
File "C:\Users\~\PycharmProjects\pythonProject\venv\lib\site-packages\pip\_internal\cli\main.py", line 68, in main
command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
File "C:\Users\~\PycharmProjects\pythonProject\venv\lib\site-packages\pip\_internal\commands\__init__.py", line 114, in create_command
module = importlib.import_module(module_path)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\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 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "C:\Users\~\PycharmProjects\pythonProject\venv\lib\site-packages\pip\_internal\commands\install.py", line 13, in <module>
from pip._internal.cache import WheelCache
ModuleNotFoundError: No module named 'pip._internal.cache'
Looking at the error, I found it's related to "caches", And I wrote a program which deletes all files which contains "cache" in it's name a few days ago since my computer is full of cache before.
My question is: Is it possible to add back the pip cache file back?
Looking forward to replys and answers.
Edit: Errors returned by using "pip install":
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\terence\PycharmProjects\pythonProject\venv\lib\site-packages\pip\__main__.py", line 31, in <module>
sys.exit(_main())
File "C:\Users\terence\PycharmProjects\pythonProject\venv\lib\site-packages\pip\_internal\cli\main.py", line 68, in main
command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
File "C:\Users\terence\PycharmProjects\pythonProject\venv\lib\site-packages\pip\_internal\commands\__init__.py", line 114, in create_command
module = importlib.import_module(module_path)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\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 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "C:\Users\terence\PycharmProjects\pythonProject\venv\lib\site-packages\pip\_internal\commands\uninstall.py", line 9, in <module>
from pip._internal.cli.req_command import SessionCommandMixin, warn_if_run_as_root
File "C:\Users\terence\PycharmProjects\pythonProject\venv\lib\site-packages\pip\_internal\cli\req_command.py", line 15, in <module>
from pip._internal.cache import WheelCache
ModuleNotFoundError: No module named 'pip._internal.cache'
The error message "ModuleNotFoundError: No module named 'pip._internal.cache'" typically indicates that there is an issue with the version of pip that you have installed on your system. This error message occurs when the module 'pip._internal.cache' is not found in the version of pip that you are using.
To fix this error, you can try upgrading pip to the latest version by running the command:
pip install --upgrade pip
If the issue persists, you can try uninstalling and reinstalling pip using the command:
python -m pip uninstall pip
And then
python -m pip install pip
Alternatively, you can try installing the package using the following command:
python -m pip install package_name
It's also possible that you have multiple versions of python installed on your system, and the one you're using doesn't have pip package. In this case, you can try running the above command with the python version that has pip installed.
It's also a good practice to use virtual environments to keep the dependencies and packages isolated.
Please let me know if there's anything else I can help with.
As you python environment is broken, I'd recommend you to reinstall pip.
If that doesn't work, just reinstall python.
Also, better don't delete all files with a specific name-pattern.
You (as you see) just break programms with it.
Better delete all files in you temp folder (%temp% in windows)
I want use search library in django
So i decide to use django-watson(it tell me easy install, easy use)
I command
git clone https://github.com/etianen/django-watson.git
in my django projects
and insert watson in my settings.py. INSTALLED_APPS
when I command
python manage.py migrate
django can't find watson so I decide uninstall django-watson and reinstall
I command
rm -rf django-watson
and command migrate (check about when i was uninstall library migrate has no problem)
python manage.py migrate
suddenly it show me error for me
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/hanminsoo/.pyenv/versions/study_alone/lib/python3.5/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/Users/hanminsoo/.pyenv/versions/study_alone/lib/python3.5/site-packages/django/core/management/__init__.py", line 327, in execute
django.setup()
File "/Users/hanminsoo/.pyenv/versions/study_alone/lib/python3.5/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/hanminsoo/.pyenv/versions/study_alone/lib/python3.5/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/Users/hanminsoo/.pyenv/versions/study_alone/lib/python3.5/site-packages/django/apps/config.py", line 116, in create
mod = import_module(mod_path)
File "/Users/hanminsoo/.pyenv/versions/3.5.1/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
ImportError: No module named 'django-watson'
I think it has installed in env but i can't find where is django-watson
I want remove django-watson clearly
please somebody help me
Make sure you have removed it from INSTALLED_APPS in settings.py and that you have removed all imports related to it inside your project.
As said, you have to remove django-watson from your installed apps. But that was the original mistake: to install watson, you have to add watson to your INSTALLED_APPS, not django-watson. This is well explained in the documentation:
Install django-watson using pip: pip install django-watson.
Add 'watson' to your INSTALLED_APPS setting.
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 have been trying to set up a new django project locally with cookiecutter-django. I have followed the docs but I keep getting into errors when trying to run python manage.py migrate.
Error Traceback.
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/ubuntu/lasbrisas_project/venv/lib/python3.4/site- packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/home/ubuntu/lasbrisas_project/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 302, in execute
settings.INSTALLED_APPS
File "/home/ubuntu/lasbrisas_project/venv/lib/python3.4/site-packages/django/conf/__init__.py", line 55, in __getattr__
self._setup(name)
File "/home/ubuntu/lasbrisas_project/venv/lib/python3.4/site-packages/django/conf/__init__.py", line 43, in _setup
self._wrapped = Settings(settings_module)
File "/home/ubuntu/lasbrisas_project/venv/lib/python3.4/site-packages/django/conf/__init__.py", line 99, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/home/ubuntu/lasbrisas_project/venv/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/ubuntu/lasbrisas_project/django_condominios/config/settings/local.py", line 11, in <module>
from .common import * # noqa
File "/home/ubuntu/lasbrisas_project/django_condominios/config/settings/common.py", line 102, in <module>
'default': env.db('DATABASE_URL', default='postgres:///django_condominios'),
File "/home/ubuntu/lasbrisas_project/venv/lib/python3.4/site-packages/environ/environ.py", line 180, in db_url
return self.db_url_config(self.get_value(var, default=default), engine=engine)
File "/home/ubuntu/lasbrisas_project/venv/lib/python3.4/site-packages/environ/environ.py", line 371, in db_url_config
'PORT': _cast_int(url.port),
File "/usr/lib/python3.4/urllib/parse.py", line 156, in port
port = int(port, 10)
ValueError: invalid literal for int() with base 10: 'jd#uhUhey385'
I don't really know what I am doing wrong while setting up the project, I'd appreciate if you check the steps I took and help me find out what is missing.
Steps taken to setup the project with cookiecutter-django:
pip, virtualenv, PostrgreSQL already installed
pip install cookiecutter
cookiecutter https://github.com/pydanny/cookiecutter-django
Answer cookiecutter questions
Creating virtualenv - virtualenv -p /usr/bin/python3 venv
Activiting virtualenv - source venv/bin/activate/
cd intoprojectfolder
Docs say sudo ./install_os_dependencies.sh install but ./install_os_dependencies.sh is not in projectroot, file found in utility/
cd utility
sudo ./install_os_dependencies.sh install
pip install -r requirements/local.txt
Setting up db in postgresql:
sudo su - postgres
psql
CREATE DATABASE myproject;
CREATE USER myprojectuser WITH PASSWORD 'password';
GRANT ALL PRIVILEGES ON DATABASE myproject TO myprojectuser;
\q
Return tu project root
mv env.example .env
export DATABASE_URL=postgres://myprojectuser:myprojectuserdbpassword#127.0.0.1:5432/myproject
python manage.py migrate
After that is when I get the traceback, what could be going wrong? The docs show no more information, the migration should work.
Cookiecutter uses the slug of the project name as the name for the development db you are to use. You are expected to create the database yourself.
from your stacktrace here is the line giving you the problem from your settings.py file:
File "/home/ubuntu/lasbrisas_project/django_condominios/config/settings/common.py", line 102, in <module>'default': env.db('DATABASE_URL', default='postgres:///django_condominios'),
It expects to find a database named django_condominios.
You can fix this by running
createdb django_condominios
and you should be good run your migrations.
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...