Python: "No virtualenv active" - python

I installed PyCharm 2.7 under Windows 8.1. It works fine, but every time I run a program, I get the following warning:
WARNING:root:No virtualenv active
Why does it happen and how can I fix it?

Program you run needs a virtual environment to run. This is a nice python feature that allows you to isolate a python program within the scope of the specific python set of libraries it may need. If you do not run more than one Python program you may not be really worried about it. However, it you do, I would recommend to ready about virtualenv first.
ps. Also, it might be just a debug log for developers to make sure they switched virtual env.

Related

Django runserver not working; error: Python was not found. Did I miss something?

It's been a while since I posted anything here, and now my problems have become more advanced. For reference, I'm running on Win10.
I'm trying to use the Django framework. Python's been installed on my computer forever; it's the latest version, and it's installed on environment variables/added to system paths. I think those are enabled by default, but I did make sure that they were checked when I reinstalled it.
pip's been updated too. Django installed successfully. I managed to get all the way to installing my new project with django-admin startproject PROJECTNAME, but when I try to run python3 manage.py runserver, I'm getting this error:
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
This "Python was not found" error is the main problem that I'm trying to figure out. Nothing I do as a fix seems to get rid of it.
...Interesting. If I type in python --version, I get a response (Python 3.11.0). Here's what I get if I do pip freeze:
asgiref==3.6.0
Django==4.1.6
sqlparse==0.4.3
tzdata==2022.7
Python IDLE runs fine; all .py files run fine. Alright. So, with that in mind and in accordance to a lot of popular advice I've seen floating around, I added the Path to my Environment Variables. For space-saving reasons, my Python is installed on my D drive rather than C. I've made sure that there weren't any leftover Python files that conflicted.
I've uninstalled and reinstalled, double checked my installations, and Django is in D:\ProgramData\Python311\Scripts with pip and everything else I need. I did also disable the shortcut from Settings > Manage App Execution Aliases, but when I did that, I got this error:
python3 : The term 'python3' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Based on some other things I've seen, I've also tried:
python manage.py runserver
python3 ./manage.py runserver
I ended up having to enable the options again just to use Python correctly. And I have been closing and reopening the command line whenever I make changes. Though it updates automatically to fit what I've been doing, I wanted to make sure I didn't overlook any possibility.
I even uninstalled Django for a third time, installed the virtual environment (which I realised I skipped), and did it all again. And then, after a long series of figuring out how to activate the virtual environment and enabling scripts to run, I'm finally in (venv) D:\PROJECTNAME, and I tried... to run it again.
I'm still getting the Python not found error. orz
I've been at it for two hours or so, and I feel like I'm running into a dead end. I think I've finally met my match here.
This is my first time using frameworks like this, and it's been a while since I've installed anything through command line on Windows. I'm not very great at this, so I know that I'm making some amateurish mistakes somewhere. Please let me know if I'm doing anything wrong or missed something obvious.
Please.... I just want to use Django....
Thanks in advance!
This question really is not proper for a PowerShell Q&A, but let see if the below helps.
If you are trying to run django from PS, then:
pip install django
django-admin startproject YourProjectNamehere
lastly, hit your dev server
HTTP://YourDevServerName:YourDevServerPortNumber
Also, be sure that you've activated your virtual environment, never assume it is until you test it. Of course, be sure to change directly to the root of your project.
Again, if you are using python, directly, then, it's more prudent to stay in your pristine python shell vs executing from a PowerShell consoler/terminal, thus eliminating any PowerShell particulars.
first download manually python on your computer , therefore install django from official website , www.python.org/downloads/, https://www.djangoproject.com/download/,
if you're on linux, pip install Django==4.1.6
after installing that use ,
django-admin

How to use python console of pycharm with a poetry environment?

Context : I am trying to find the best environment to develop analytics ml project in python where I can both write my main pipeline functions as a script (and access variable through a console) and then do analytic on notebooks.
Each project is different and so I am defining new poetry env to settle the right python packages. At each step when running my script I need to be able to access the variables easily to debug and code faster. I am currently using pycharm as IDE, but I can't find a way to activate and use my poetry env when running a python file through the python console of pycharm. I can only choose the python version, but the packages used when running the python console seem to be the one installed globally on my computer. Being able to access variables through python console while still using poetry env would help me save a lot of time when developing my script.
If it's not possible to run python console on pycharm with poetry env, I might change IDE to go to VS Code, as some friends advice me to do. If you have any advice, I will take them gladly :) !
Thank you very much and have a nice day !

I’m using a project which is expecting Python3. How can use that without messing anything up?

I’m using a project which is calling a script where python means python3. However python -V shows version 2. I know I have both versions (python3 -V, shows expected version) installed.
How can I run a script from this project and it run the correct version of Python? I suspect I shouldn’t have to change anything like aliases or environment paths. Although I haven’t used them before, this sounds exactly like what a virtual env is for. Am I correct?
ETA:
I’m calling a script from the command line:
make foobar
Set your desired Python version on the IDE and create a virtualenv if especiall the project requires certain packages/libraries to keep it isolated and not run into certain errors down the road.

Arrow up / previous command in VSCode Python Interactive not working

I'm working with VSCode on an Ubuntu 18.04 machine. Everything is fine except that I can't get back to the previous command in Python Interactive Window via Arrow Up. It works in the integrated terminal though, integrated shell is /bin/bash.
I have no idea where this is coming from. I changed "keyboard.dispatch" to "keyCode", but that's not the problem. I also tried different versions of the python-extension.
Do you have any idea?
Thanks!
Not sure if this is helpful for you as an Ubuntu user, but I came across the same problem in Windows this week. In my case, the issue cropped up after I installed the Python extension in VS Code (or at least I didn't notice the issue before this). The combination of using the Python extension, Git Bash for terminal, and python virtual environment killed the up arrow feature for me. Using python outside a virtual environment works fine. My solution was to use Command Prompt as the terminal when I wanted to use a virtual environment interactively.
In my situation, although I delete all the shortcuts of UpArrow, I still can get the previous command through UpArrow in Python interactive. This means there's no way to configure this shortcut, it was built in the plugin which built in Python extension.
So it's some problem with your Python extension, but you said you have tried to install a different version of Python extension but still not work. Make sure you have deleted it completely -> delete the extension folder manually(it's under C:\Users[UserName].vscode\extensions\ms-python.python-xxx).

PyCharm terminal doesn't recognize Python or Pip

I'm using PyCharm for a project, and I've been having a problem I can't understand. In the "terminal" (in PyCharm), I activate the virtualenv I want, which has Python and all my other packages. The project works, which means the packages are being found, because otherwise it wouldn't work. But the thing is, neither python nor pip are recognized in the PyCharm terminal. This happens whether the virtualenv is activated or deactivated, so I don't think that's the issue.
I get the "python is not a recognized internal or external command" message, but if I do it in the file system, for instance, I can use python, pip, and everything else just fine, so I think it might be a configuration of my PyCharm, most likely, but I don't even know where to look, I don't see anything in the settings that I find odd. Any help could save me a lot of time I've been stuck with this. I'm on Windows 10, by the way.
The environment variable 'PATH' is 'C:\Users\Iván\AppData\Local\Programs\Python\Python36', and python is recognized anywhere but within the PyCharm terminal.
If you are using windows.
You have to add paths to python & pip in environment variables. If you have no previous experience doing so. I would ask to use this link https://www.youtube.com/watch?v=DrhkbjDAUV0.
If I am getting your problem wrong sorry.

Categories

Resources