Scrapy commands not working inside project directory - python-2.7

I have set environment variable to python27/Scripts. I am able to create project by
Scrapy startproject fund
So a project fund is created. Now I go inside the directory of fund where configure file is present and here scrapy is not recognised. Say I want to generate a spider or crawl it it does not work? Please advise on how to correct this problem.

I don't know if you are working with Anaconda, but if you are, than you might have to activate the virtual environment.
open: Anaconda prompt
Write: activate [insert name of your virtual environment]
cd to the place where you want to start your project (so for example cd desktop)
write: scrapy startproject [NameOfYourProject]

Related

Not able to activate debug in VS-code for Django project (Django in virtual environment)

I have an issue running the Debug environment for Django application in VS-code:
my python is not in the virtual environment,
while my django is.
Therefore, the solution I see everywhere with adding to the launch.json settings the line "pythonPath": "${workspaceRoot}/.venv/bin/python2.7",
does not fit, and I end up having the following error:
Exception has occurred: ImportError
Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable?
Did you forget to activate a virtual environment?
When working on the application, I launch the setting environement using the following command:
.\venv\Scripts\activate.ps1
Can anyone help me out to declare my virtual environment the proper way in the launch.json file?
if you've created a virtual env lets say with python -m venv my_env, you should "select Interpreter" and define a path like this:
./my_env/bin/python
make sure you choose correct version (python2/3) and
usually there's no need to make launch.json manually.
Based on the suggestion of https://stackoverflow.com/users/13877794/omid, I was able to find the solution:
I opened command palette, chose Python: select Interpreter, and then after selecting the workspace I was interested in, I typed in .\venv\Scripts\python.exe which works fine for me.

How can I get PyCharm to use the Vagrant Directories rather than my development machines?

When I try to run my Django app via PyCharm inside of Vagrant, it sends my Windows Path over SSH which then provides an error in the shell:
> ssh://vagrant#127.0.0.1:2200/usr/bin/python -u C:/Projects/dev_project/dev/manage.py runserver 0.0.0.0:8000
bash: line 0: cd:
C:/Projects/dev_project/dev: No such
file or directory /usr/bin/python: can't open file
'C:/Projects/dev_project/dev/manage.py':
[Errno 2] No such file or directory
I created a Python Project in PyCharm (and instantiated a Django Project in a sub-folder) in order to incorporate Vagrant.
dev_project (PyCharm project root)
|--.vagrant
|--dev (Django project root)
|--dev
|--app
|--manage.py
|--Vagrantfile
In Settings
I enabled Django Support (providing the Windows Paths as there is no other option) in Settings > Languages & Frameworks > Django.
The Vagrant Python Interpreter is selected as the Project Interpreter (and Django Console & Python Console)
In Run Configurations
My host is 0.0.0.0 and port is 8000
My Python Interpreter is the Vagrant Environment. I am also adding the Content Roots & Source Roots to the Python Path.
The bizarre problem is it was working fine, and then I exited out and it broke again. Also, I do not have 'Working Directory' explicitly defined anywhere.
This blog article showed me my issue, as I did not have my Path Mappings setup within my Run Configuration.
From the Article (Configure Your Project to Use the Correct Interpreter):
Select Run->Edit Configurations…
Select the configuration on the right PyCharm created for us. In my case it was called “session_tracker”.
Change “Python interpreter” to our newly created one.
A new field will appear. Click the button next to “Path mappings”. A new window will appear to let you create your mappings.
Vagrant shares a local directory with the VM. My Vagrant file is configured so a folder is called “django_shared” in our [VagrantFolder] locally, and “django_shared” in the home directory on the VM are the same. You need to enter the full paths of each of those in the “Edit Path Mappings” window. - Click the + button to create a new mapping, then enter the values for the mapping on each side.
When no other option works I do the following:
Create seperate virtualenv in my local directory
Reconfigure PyCharm to use the interpreter in that venv
Restart PyCharm
Maybe not a very good solution, but works.

Virtualenvwrapper not using project_home

I installed virtualenvwrapper on ubuntu. I added the following lines to the top of bashrc file:
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/myprojects
source /usr/local/bin/virtualenvwrapper.sh
everething works perfect except that when I use django-admin start project command, the project gets created in my home directory not the directory I specified in bashrc file which is myprojects.
shouldn't new projects be created in myprojects folder?
thanks in advance.
I assume you're running django-admin startproject in your home folder? django-admin doesn't know anything about virtualenvwrapper and, unless you explicitly specify a folder, it creates the project in the current folder. See https://docs.djangoproject.com/en/dev/ref/django-admin/#startproject-projectname-destination

Django management task won't work on CentOS in crontab or outside project directory

On my local machine (Mac OSX 10.6) I wrote a django custom admin command which works great. I can use it both within and outside my project directory just fine. For some reason on my CentOS 5.6 server, it won't work from outside the project directory. This is really annoying since using this custom admin command in a cron job requires it to run from the home directory.
in short:
When I run "python ./manage.py scrape" or "python manage.py scrape", everything is fine.
When I run "python /home/[username]/webapps/myproject/manage.py scrape" or "python myproject/manage.py scrape", I get the following error:
unknown command: 'scrape'
Type 'manage.py help' for usage.
On CentOS, when I run manage.py help inside the project directory, scrape shows up as a command; but if I run it outside the project directory, scrape does not appear as a valid command. On OS-X scrape appears as a valid command regardless of where I run manage.py help from.
Any idea how I can fix this?
I know CentOS ships with Python 2.4, so is your code running on 2.4 or are you using a contained environment, this is usually fixed by adding your PYTHONPATH correctly
import sys
print sys.path
verify such for starters
This should get you up and running: http://djangosnippets.org/snippets/374/

Django + Virtualenv: manage.py commands fail with ImportError of project name

This is blowing my mind because it's probably an easy solution, but I can't figure out what could be causing this.
So I have a new dev box and am setting everything up. I installed virtualenv, created a new environment for my project under ~/.virtualenvs/projectname
Then, I cloned my project from github into my projects directory. Nothing fancy here. There are no .pyc files sitting around so it's a clean slate of code.
Then, I activated my virtualenv and installed Django via pip. All looks good so far.
Then, I run python manage.py syncdb within my project dir. This is where I get confused:
ImportError: No module named projectname
So I figured I may have had some references of projectname within my code. So I grep (ack, actually) through my code base and I find nothing of the sorts.
So now I'm at a loss, given this environment why am I getting an ImportError on a module named projectname that isn't referenced anywhere in my code?
I look forward to a solution .. thanks guys!
Is projectname exactly (modulo suffix) the name of the directory the project is in? Wild guess, but I know Django does some things with the current directory…
Also, what is trying to import projectname? Do you get a traceback? If not, try running with py manage.py --traceback syncdb and see what happens.