I can't run the script and make a virtual environment - python

I'm trying to install a virtual environment in order to work with libraries, but it absolutely does not work
python : The name "python" is not recognized as the name of a cmdlet, function, script file, or executable program. Check the spelling of the name, as well as the presence and correctness of the path, and then try again.
line:1 sign:1
python -m venv scrap
+ CategoryInfo : ObjectNotFound: (python:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

On Windows, you need to add Python to your PATH. Try this How to add Python to PATH
And check if Python is installed correctly and restart your PC on this Question restarting the PC helped

You need to add the path to your environment variables.
You should go to Control Panel>System and Security>System>Advanced System Settings>Environment Variables
Then select edit PATH and append the path to your python executable:
C:\Users\{your_user}\AppData\Local\Programs\Python\{your_python_executable}

Related

How do I activate my virtual environment using PyCharm? Can I even activate it in PyCharm?

I have am slightly confused about the local and command prompt in the terminal section of PyCharm. Could someone explain to me what the differences are?
Also, how do i activate my virtual environment from PyCharm, as i need it to run selenium (i placed it in a separate virtual environment). Do I use command prompt or local. I tried using local and when i type activate.bat in my Scripts folder, I come across this error message:
activate.bat : The term 'activate.bat' 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.
At line:1 char:1
activate.bat
+ CategoryInfo : ObjectNotFound: (activate.bat:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Suggestion [3,General]: The command activate.bat was not found, but does exist in the current location. Windows PowerShell does not load commands from the current location by default. If you trust this command, instead type: ".\activat
e.bat". See "get-help about_Command_Precedence" for more details.
PS C:\Users\Jonathan\venvs\automation\Scripts>
Can someone assist me on how i can activate my virtual enviornment via PyCharm?
Yes, you can activate your virtual environment in Pycharm. Pycharm configures an interpreter for each project, and by default uses the system Python interpreter if not otherwise specified. To use the virtual environment's interpreter do the following:
Settings > Project > Python Interpreter
Click on the cog next to the path, and select Add... to add a new interpreter
Select existing environment, and enter the path of the venv
Click OK
After doing this Pycharm will do some indexing, and the next time you run your program it should run using that virtual environment.

Virtual Environment won't activate on Windows 10

I use Windows 10, python 3.7.4 and i've installed virtualenv with pip.
When i try to create virtual environment in cmd i can create with virtualenv myenv.It creates the files needed, Scripts folder and activate files are all there. But when i try to activate nothing happens. I try:
C:\Users\Spike\pyenv>cd crawler
C:\Users\Spike\pyenv\crawler>cd scripts
C:\Users\Spike\pyenv\crawler\Scripts>activate
After this virtual environment name should be in parenthesis like this:
(crawler) C:\Users\Spike\pyenv\crawler\Scripts
but it is not, virtual env is not activated, it continues like this:
C:\Users\Spike\pyenv\crawler\Scripts>
I've tried running cmd in admin mode, doesn't work.
I've tried to activate from Powershell:
PS C:\Users\Spike\pyenv\crawler> cd scripts
PS C:\Users\Spike\pyenv\crawler\scripts> activate
But i get a error:
activate : The term 'activate' 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.
At line:1 char:1
+ activate
+ ~~~~~~~~
+ CategoryInfo : ObjectNotFound: (activate:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
So i've tried Set-ExecutionPolicy AllSigned and Set-ExecutionPolicy Unrestricted -Force on Powershell before activating it, it also doesn't work.
I've also tried to activate it in cmder, i get the same result i got in cmd.
To solve i first looked in to other stackoverflow thread but none helped.
Check the name of your virtualenv. You said the name of your env was myenv. However, you are in the pyenv directory. If you CD to the folder you where in when you created myenv, the following should work.
myenv/Sripts/activate
If that does not work, make sure the activate file is actually there.
Also, note that in certain cases the virtualenv starts but you don't get the (myenv) bahavior. Run the following to see if the virtualenv is activated.
which python

How to setup a virtual environment for python in Visual Studio Code using the command line

I am a very new programmer trying to learn Flask now that I've learned the basics of Python. I am following this tutorial https://www.youtube.com/watch?v=Z1RJmh_OqeA&t=355s ... I am stuck at 5:46.
The tutorial, as well as documentation on several other websites, explains to type in the following command:\env\Scripts\activate.bat for Windows, and they suggest using:source env/bin/activate for Mac.
This is what I get in return:
\env\Scripts\activate.bat : The term '\env\Scripts\activate.bat' 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.
At line:1 char:1
+ \env\Scripts\activate.bat
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (\env\Scripts\activate.bat:String) [], CommandNotFoundEx
ception
+ FullyQualifiedErrorId : CommandNotFoundException
Suggestion [3,General]: The command \env\Scripts\activate.bat was not found, but does exist in the current location. Windows PowerShell does not load commands from the current location by default. If you trust this command, instead type: ".\\env\Scripts\activate.bat". See "get-help about_Command_Precedence" for more details.
Until this point everything else had gone smoothly.This is what I've done leading up to this point:
pip3 install virtualenv
virtualenv env
After running these commands, the tutorial asks me to run the command I'm having problems with.
What options do I have to fix this??
You probably have not set the path variable so the system can't find the Scripts folder. In a typical Python installation on Windows (which you seem to be using), Python is installed under the C drive in Program Files, and inside that directory is the Scripts directory, which is where virtualenv.exe lives.
So you need to open Control Panel, go to System, click on Advanced System Settings, click on Environment Variables, then under USER variables highlight Path, click on Edit, and see if the path to Scripts exists; it'll be something like:
C:\Program Files\Python37\Scripts
If it's not there you need to click New and enter it.
I think you should add . before the \env\... path. This implies that, instead \env\Scripts\activate.bat do .\env\Scripts\activate.
Moreover, you can navigate to the venv\Scripts\ folder and type activate.
copy this term and past your command line in your PyCharm and enter:
.\activate

Django command giving error

I am new to Django and Python having trouble with a Django command.
Before the query, I want to let you know that
1) python is installed in my c drive and the path name is C:\Users\admin67\AppDathea\Local\Programs\Python\Python37
2) The Djangp project is in the D drive and the path name is D://wisdompets
3) My python version is python 3.7.0
In the windows shell I give the command python3 manage.py runserver
However this command is not running in my windows shell. I have tried all combinations such as python370, python37, python 3.7..0 but nothing works and I keep getting the message (see the attachment).
The error traceback that I get in the Windows shell is as below.
The term 'python3' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spe lling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:8 + python3 <<<< manage.py runserver + CategoryInfo : ObjectNotFound: (python3:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
Please help me resolve this error.
Thanks & Regards Manish
Your Python PATH variable is not configured properly. Having Django project and Python interpreter in different locations is not the problem here. The CMD will find the python.exe from the PATH variable defined in the system. If it can't find it then it will raise an error.
Please go to PATH in your Environment variables (Right click on This PC > Properties > Advanced System Settings > Environment Variables
And check if that exact path of your python.exe(That you mentioned) is there in your PATH. It likely isn't there and that's the reason you're seeing this error.
To resolve it,
Click on Path variable and edit it. Now add the directory where your Python is installed. i.e "C:\Users\admin67\AppDathea\Local\Programs\Python\Python37" ,
Restart your CMD or PowerShell and Python should now be recognized.
pip also must now be recognized and then 'pip install django==1.11.7' in your cmd, as that is what wisdompets need. If you don't specify the version it will fetch the latest version(Django 2.1 as of now) and entire code will break.
Now in your CMD.
python manage.py runserver
Hope this helps !

Python 3.6 isn't runnable through Command Prompt

Problem:
I have included Python's install path (C:\Program Files\Python36) on both
the "Path" and "PYTHONPATH" system variables. I haven't needed to use Python for a while, and I am certain it worked last time (close to a few months ago). Python IDLE still works, but I need to use Python through the command prompt.
Every other similar question I found online was usually resolved with making the proper changes to the system variables.
Error message when attempting to execute any Python-related task:
python : The term 'python' 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.
At line:1 char:1
+ python
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (python:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
What I've done so far:
Set system variables to Python Path via Control Panel>System and Security>System>Advanced System Settings>Environment Variables
Tried using cd to use python directly from it's install location
Solution:
Python's install path was overridden by Visual Studio to it's "shared" location (more like pain-in-the-ass location) located at:
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\
Changing both system variables(Path and PYTHONPATH) to this location resolved this issue.
Thank you to all who commented/responded.
EDIT: Apparently it is bad practice to manually set PYTHONPATH, as it is automatically set by Python.

Categories