mac ox 8.2, eclipse juno, python 2.7, django 1.4.1, pydev 2.7.1.2012100913
I'm relative new with python/django and I'm trying to get it to work with pydev in a virtualenvironment. I set up the virtualenvironment installed django and successfully created and started a django project. After that I decided that I want to use my favorite editor eclipse.
I created a new pydev/django project, configured and selected a new interpreter (from virtualenv) and used that, I also included the virtualenv/lib/python2.7/site-packages/django in the interpreter libraries. However after going the next dialog, I got an error message "Django not found"
I went over the documentation but I haven't found any solution yet.
I was also wondering whether the workenvironment (or the actual code) needs to live in a subdirectory of the virtualenv directory) And whether the virtualenv must be activated (I suppose so), tried all these options but no luck yet.
As far as I'm aware you don't need the django installation (i.e., virtualenv/lib/python2.7/site-packages/django) in your interpreter libraries. Having the site-packages in there (i.e., virtualenv/lib/python2.7/site-packages) should suffice for your interpreter to find any django.* package.
putting this in your interpreter libraries:
virtualenv/lib/python2.7/site-packages/django
wiil not work, because there is no virtualenv/lib/python2.7/site-packages/django/django (yes, twice), this translates to the following:
export PYTHONPATH=<...virtualenv>/lib/python2.7/site-packages/django:$PYTHONPATH
python -c 'import django'
which fails with ImportError message. you need to give the parent directory.
virtualenv/lib/python2.7/site-packages
which translates to the following:
export PYTHONPATH=<...virtualenv>/lib/python2.7/site-packages:$PYTHONPATH
python -c 'import django'
.
Related
I just installed the new python3 module using terminal of Visual Studio Code on ubuntu.
When I import it, this error occurred.
[Python (analysis)] Unable to resolve 'new module'. IntelliSense may be missing for this module.
But the new module surely installed successfully. (I can import it in my ubuntu terminal)
How can I import that new python module in VS code?
You should look up the official docs on it. They have a neat tutorial to get you started.
Here are a few excerpts that should help you:
An "environment" in Python is the context in which a Python program runs. An environment consists of an interpreter and any number of installed packages. Because many programs are written specifically for a certain Python interpreter and makes use of a set of libraries, developers often create and manage an environment for individual programs.
When working with Python in VS Code, you select from available environments using the Python: Select Interpreter command. The Python extension then uses that selected environment for IntelliSense, auto-completions, linting, formatting, and any other language-related features. (The environment is not, however, used for debugging; see Choose a debugging environment.)
The selected environment is also automatically activated when using the Python: Run Python File in Terminal and Python: Create Terminal commands. Installing (or uninstalling) a package in the Terminal with a command like pip install matplotlib installs (or uninstalls) the package in whatever environment is active in that Terminal.
Note: By default, the Python extension looks for and uses on the first Python interpreter it finds in the system path. If it doesn't find an interpreter, it issues a warning. On macOS, the extension also issues a warning if you're using the OS-installed Python interpreter, because you typically want to use an interpreter you install directly. In either case, you can disable these warnings by setting python.disableInstallationCheck to true in your user settings.
I watched a tutorial that requires me to have Django 2.1.
When I type in "python -m django --version" - my Ubuntu terminal says 1.11.18 But, when I type "django-admin --version" - terminal says 2.1 This didn't bother me until I reached part 6 of this series, I'm heavily invested now with a serious problem I can't figure out. I even completely reinstalled my OS, (I was running Linux mint, thought it'd be easier if I ran Ubuntu) I ran through a myriad of different "fixes" I found online, but nothing seemed to fix this.
The main issue that I ran into from the tutorial is the urls linking.
EDIT:
I have Python 3.6 installed
You need to be using Python-3 to use Django-2.1. Django 1.11 is the last version to support Python 2.7.
The problem is most likely because you've got both Python 2 and Python 3 installed on your system, and you're installing Django without a virtual environment. I would highly recommend using a virtual environment: it keeps your project separated from the system Python version's packages. At this point, using Python 3 and venv to make your virtual environment is the best practice.
See the documentation here: https://docs.python.org/3/library/venv.html#creating-virtual-environments
Here's a quick walkthrough to create a new virtual environment in a directory called "my_django_project" in your home directory with Python 3 and install Django:
python3 -m venv ~/my_django_project
pip install Django
. ~/my_django_project/bin/activate
To deactivate your virtual environment, type deactivate.
Then, whenever you want to work on this project, type . ~/my_django_project/bin/activate.
Now let's say you wanted to work on a separate project using another Python package, like OpenCV. You could create a separate virtual environment for this project:
python3 -m venv ~/my_opencv_project
pip install opencv
. ~/my_opencv_project/bin/activate
This allowed you to keep your projects separate. There is a fair amount more to learn, but this should be enough to get you started. Good luck!
I keep trying to set up a project with Eclipse Neon Release Candidate 3(4.6.ORC3) and PyDev 5.1.1 and keep having the same problem. Going to Project > Properties > PyDev-Django screen, I keep getting the same error Settings Module could not be found. I have tried everything to try to fix this error, including manually filling in the DJANGO_SETTINGS_MODULE manually. Nothing works. The problem really exist because manage.py tests and runserver return the same error. The settings.py file exists and is in the correct place in the project directory. I am dead in the water untill I get this fixed.
Note: I upgraded the system to Neon 4.6 and PyDev 5.1.2 . I still have the same problem
Using Debian Linux Stretch with KDE Desktop.
Please help.
Gary R.
Before adding the project to the python path
Adding the python path to the project:
now pythonpath is added to the project
After adding python path to the project settings module is found
I am using: django 1.10, pydev 5.2
Make sure the PyDEV PYTHONPATH settings includes the directory where manage.py lives.
For my django projects I have created a nice working workflow. Using buildout to 'bootstrap' a project and the apps I have developed based on versions. The rest are packages and apps installed from pypi. I work on ubuntu, and my servers are on ubuntu. This works like a charm.
Now there is a new developer who works on windows. He has a lot of troubles getting the buildout working the same way I Am using it.
Is there a special way or other way I should use buildout for setting it up for windows?
the usage of easy install seems to be the problem....
Windows user:
I have installed numpy and matplotlib with installers for windows(x64). But buildout still tries to compile matplotlib. The compilation is not working. I tried GCC as a compiler. Can I prevent buildout from compiling and using the installed packages?
If something has a dependency on numpy or matplotlib, buildout will try to install it, period. So you have two basic solutions:
Don't explicitly say you want numpy or matplotlib. Depend on it that you and your colleague already installed it globally. Buildout won't try to install what it doesn't know about :-)
Use syseggrecipe to explicitly tell buildout to look for a package in your global install:
[buildout]
parts =
sysegg
django
....
[sysegg]
recipe = syseggrecipe
eggs =
matplotlib
numpy
[django]
recipe = djangorecipe
....
Make sure the sysegg part is pretty much right at the start of your parts list. syseggrecipe places a link to your globally installed version in your buildout's develop-eggs/ directory, thereby telling buildout about the package's existence.
Warning: I'm not sure is syseggrecipe works 100% on windows, as it uses symlinks. Pull requests that fix it (if it turns out to be a problem) are welcome.
I recently started working on a project using just vim as my text editor with a virtualenv setup. I installed a few API's on this virtualenv from GitHub. Eventually, the project got a little bigger than vim could handle so I had to move the project to an IDE.
I chose Aptana Studio 3. When I started up Aptana, I pointed the project directory to the virtualenv folder that I had created to house my project. I then pointed the interpreter at the Python executable in App/bin (created from virtualenv)/python2.7. When I started reworking the code to make sure I had everything mapped correctly, I was able to import the API's that I had installed just fine. CherryPy came through with no problems, but I've been having an issue with importing a module that I believe is part of the stdlib--urlparse. At first, I thought it was that my python interpreter was 2.7.1 rather than 2.7.5 (I found the documentation in the 2.7.5 section with no option to review 2.7.1), but my terminal is using 2.7.1 and is able to import the module without any errors (I'm using OSX, Mountain Lion). I am also able to import the module when I activate the virtualenv and run my python interpreter. But when I plug "from urlparse import parse_qsl" into Aptana, I'm getting an error: "Unresolved_import: parse_qsl".
Should I have pointed this at a different interpreter and, if so, will I need to reinstall the API modules I had been working with in the new interpreter?
Update: I finally ended up restarting the project. It turns out that not all of the standard Python tools are selected when you select the virtualenv interpreter. After I selected all of the python tools from the list (just after choosing the interpreter), I was able to get access to the entire standard library.
Do NOT just import the modules into your project. Many of the stdlib modules are interdependent and the import function will only import a module into your main project directory, not a libary!