I spent a good deal of time the past two days trying to use poetry correctly. I'm not new to poetry and have used it for a while. But in this DJANGO project I just started with a buddy, after adding packages, some of them needed to be added again via 'python -m pip install '. Once I did that, the django project passed a check and I could also migrate tables. It really bothers me that I'm using a virtual management package that doesn't appear to always work. I like poetry and want to use it. Some of the packages I had to pip install are django and pymysql. I also use pyenv. I'm running python version 3.10.6. I did things such as deleting the .venv folder (mine gets created in the project directory) checking with pip freeze that these packages are not already installed, and then doing a poetry update to re-create .venv. Any suggestions or ideas? I really need to focus on my django project and not be farting around all the time with package issues so I would like to either fix this or at least have a better idea of what is going wrong so I can avoid it.
Related
I am studying Django for the first time and everything was going well until the last day. Today when I tried opening my Django project, the terminal returns an error saying :-
Unable to create process using
'C:\Users\User1\AppData\Local\Programs\Python\Python310\python.exe manage.py runserver'
Thinking that it might be an issue with the virtual env, I tried checking my Python Interpreter to make sure I am currently in my venv.
Fortunately, I am currently using my venv but Pycharm indicates me to Install Python Packaging Tools.
I tried the link to install it but it notifies a Non Zero Exit Code(101) and Invalid Python SDK error.
Googling for the error asked me to check the path in Environment Variables where two are present -
C:\Users\User1\AppData\Local\Programs\Python\Python310\
C:\Users\User1\AppData\Local\Programs\Python\Python310\Scripts\
Recently I had added MingW Compiler to the path and that was it. I've never touched the path of Python.
I would like to mention that there are no errors in creating a new virtual envirnoment nor activating it. But things get worse when I try to pip install django. CMD tells that unable to create process.
Please help! I am actually stuck with my project.
Happy to say that I have fixed the issue.
Steps followed include :
Uninstalled Python,Deleted Path,Restarted my pc
Downloaded and Installed Python 3.10.2 from the official site.
Upgraded pip
Installed virtualenv using pip install virtualenv
Tested it creating env using - py -m venv "environment name"
pip install django works + started a project and the setup was successful.
First, try to run any python file (not in your project).
If it works, then the problem is with your django project or the env (try to create a new env and move your files to it).
At last, I think you should reinstall python; this will fix the problem I guess.
My question is do i have to install django every single time in my virtual environment in order to run my python files? and is this taking up bunch of space on my machine? My project also uses "matplotlib" and every virtual environment i create it also asks me to import the matplotlib module too. its getting annoying. do i have to do this every time?
Im new to Django. I wanted to run some python files in django but they weren't working, so after some research i found out i needed to run my pycharm project in a virtual environment in order to run these python files.
my folders look like this pycharmProjects -> my project
I enter pycharmProjects and I set up virtual environment using "pienv shell". Then i run "python3 manage.py runserver". It turns out i must install django in the virtual environment before the files run.
Short answer is no, you don't have to use a virtual environment at all and can install your dependancies globally instead. However you will soon find that it will cause a lot of issues. The main reason you would create a virtual environment is to give control of your dependancies and prevent bugs that could be caused because of them having their wires crossed between projects.
Short answer yes.
If you create a virualenv you have to install all packages, that your program needs.
Long answer:
You could install django system wide and then create a virtualenv with the option
--system-site-packages then django would be used from your globally installed python.
(Or you install everything just in your global python, put I personally don't think this is good practice)
If you work with many different projects I think you will avoid a lot of trouble if you use one virtualenv per project.
Trouble meaning that one project breaks, because one pip install for another project changed the version of one package and one project can't handle the newer version.
I would recommend to create a requirements.txt file for each project, that lists the dependencies then you can create the virtualenv with following command
pip install -r requirements.txt
if you have requirement.txt files, then you can create virtualenvs rather quickly if going back to an old project and you can delete the virtualenvs whenever you run out of disk space. If you want to be an the safe side, type pip freeze > pipfreeze.txt prior to deleting the virtualenv and use pip install -r pipfreeze.txt if you want to create one with the same modules and the same versions.
You also might want to look at direnv or autoenv if working on a linux like system.
This will automatically switch to the required virtualenv when changing to a project's working directory.
I am working on several projects on the same PyCharm. Like I "attached" them all together. But I recently noticed some weird behaviors. Like when I import a library I haven't installed yet to my script. It shows me a little error as expected. But when I try to install that using python -m pip install my_library, it tells me that it has already installed. I recently noticed that this is because it's using and other pip from another project. I doesn't use the one in the venv folder in the project. Also to run the scripts sometimes it uses python.exe from pythons original directory. It's a whole mess and I have no idea how I can solve it. Sometimes my projects requires different versions of the same library and you can imagine what happens when I change the version.
I make sure each project is using their own interpreter. Don't know what else to do other than this. I am using Python3.6.4 PyCharm2018.3.2 running on Windows10
it sounds like all your projects are configured to use the system's interpreter instead of the virtual environment you set up for each of them.
Follow this instruction to fix it https://www.jetbrains.com/help/pycharm-edu/creating-virtual-environment.html
In terms of using different version of the python library, you can address that by specifying it in requirements.txt file, which you can put in your venv folder for each project. then you can just do pip install -r requirements.txt after you set up your venv. (you need to ensure that the venv is activated - you don't need to worry about this if you have configured the project in PyCharm to use the venv's python interpreter.) You can check this by going to Terminal in your PyCharm and you should see (venv_name) hostusername#host:~/project_folder$
I'm trying to setup a Django project and am a bit stumped on this part of setting everything up.
I've ran pip install django and tried running django by doing
python
import django
but I immediately get a message ImportError: no module named Django
I've tried going to the folder /usr/local/lib/python2.6/site-packages but there is nothing in that folder. If I go to /usr/local/lib/python2.6/dist-packages, all of my modules are there including django. Now should everything go in the site-packages folder? I'm really confused as to why django isn't running the way it should be. I tried reading the Django documentation but that assumes my installation correctly goes into .../site-packages
Are you sure that you are using "Virtualenv", if not than you should think about using virtualenv. I suspect you are not using it and doing a system install of Django.
So make sure that Django is getting installed properly. May be that you dont have the user rights to make a system wide install, so try to do sudo pip install django.
Hope it works out for you, if not try to be more descriptive of your problem.
Use pip install Django.
For some reason they used a capital 'D' in Django instead of the normal all lower case. Source:Django Documentation.
Also make sure that/usr/local/lib/python2.6/dist-packages is added to your PATH.
The normal behavior of pip is to install into the site-packages folder. Maybe try re-installing pip?
You should set up a virtualenv, especially if you're going to be making several Django applications that have different requirements. You also have to run pip with sudo so sudo pip install django. To learn how to make a virtualenv: http://www.virtualenv.org/en/latest/ .
You can also check your $PATH variable to see if /usr/local/lib/python2.6/dist-packages is there, if it's not you can add with by adding the following to your .bash_profile
PATH="${PATH}:/usr/local/lib/python2.6/dist-packages"
export PATH
Under virtualenv, you don't have to use sudo pip, instead cd (change directory) to your environment directory, and run pip install django and it will only install it for that project.
So, I want to start using virtualenv this year. I like the no-site-packages option, that is nice. However I was wondering how to install certain packages into each virtualenv. For example, lets say I want to install django into each virtualenv... is this possible, and if so, how? Does buildout address this?
Well it's not so much django, more like the django applications... I dont mind installing a version of django into each virtualenv... i was just wondering if there was some intermediate option to 'no-site-packages'
I know where you're coming from with the no-sites-option. I want to use pip freeze to generate requirements lists and don't want a lot of extra cruft in site-packages. I also need to use multiple versions of django as I have legacy projects I haven't upgraded (some old svn checkouts (pre1.0), some 1.0, and some new svn checkouts). Installing Django in the global site-packages isn't really an option.
Instead I have a django folder with releases and a couple of different svn versions and just symlink to the appropriate version in the local site-packages. For ease of use I link to the local site-packages at the same level as the environment and then link in the appropriate django directory and any other "system" style packages I need (usually just PIL). So:
$ virtualenv pyenv
$ ln -s ./pyenv/lib/python2.5/site-packages ./installed
$ ln -s /usr/lib/python2.5/site-packages/PIL ./installed
$ ln -s /opt/django/django1.0svn/trunk/django ./installed
Now the following works:
$ source pyenv/bin/activate
$ python
> import django
> import PIL
If you want django to be installed on EACH virtualenv, you might as well install it in the site-packages directory? Just a thought.
I'd suggest using virtualenv's bootstrapping support. This allows you to execute arbitrary Python after the virtualenv is created, such as installing new packages.
The other option (one I've used) is to easy_install Django after you've created the virtual environment. This is easily scripted. The penalty you pay is waiting for Django installation in each of your virtual environments.
I'm with Toby, though: Unless there's a compelling reason why you have to have a separate copy of Django in each virtual environment, you should just consider installing it in your main Python area, and allowing each virtual environment to use it from there.
I want to check out this project:
http://www.stereoplex.com/two-voices/fez-djangoskel-django-projects-and-apps-as-eggs
Might be my answer....