The command source sandbox/bin/activate doesn't work in powershell - python

I just start the course "Building Neo4j Applications with Python" in Neo4j Graph Academy. In the course I created a virtual environment named sandbox with python -m venv sandbox but when I want to activate with the code indicated in the course: source sandbox/bin/activate the powershell console shows this error:
source : The term 'source' is not recognized as the name of a cmdlet, function, script file.
script or executable program. Check if you spelled the name correctly, or if you included a
path, check that the path is correct and try again.
On line: 1 Character: 1
+ source sandbox/bin/activate
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (source:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

This looks like you are on Windows, using PowerShell, and trying to activate the virtual environment with the bash/zsh script meant for Unix systems.
Instead, try running
sandbox\Scripts\Activate.ps1
You can find the full documentation with more details and things to consider here: https://docs.python.org/3/library/venv.html
Make sure to give it a good read.

Related

env : The term 'env' is not recognized as the name

I am new to coding and I am learning about environment variables in python using pycharm. I am trying to hide my API KEY in the terminal for basic security however when I type env into the terminal this is the response.
env : The term 'env' 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
+ CategoryInfo : ObjectNotFound: (env:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
How can I fix this? How can I fix the path or find the path?
env is not a program installed by default on Windows, you're probably thinking of the env command commonly used on Linux and Unix based systems to display your environment. The equivalent Windows command is Get-ChildItem Env: for PowerShell, and SET in command prompt (Thanks #ᴓᴓᴓ!)

Python does not run command

I am trying to run a simple command in a .py file on Visual Studio Code, namely:
import os
I get the following return in the terminal:
& : The term 'C:/Users/Tim-S/anaconda3/envs/plotlyenv/python.exe' 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:3
+ & C:/Users/Tim-S/anaconda3/envs/plotlyenv/python.exe "c:/Users/Tim-S/ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:/Users/Tim-S/...yenv/python.exe:String)
[], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Can anyone explain me how I can solve this?
Start by installing Python from python.org or choco. Then, in your terminal (cmd, powershell, windows terminal, etc.), run python. Only then, should you attempt to run anything in VS Code.
You may already be having success up to that point, but it isn't clear from your question. I can see you have some environment (anaconda) installed. There are several VS Code plugins for Python. This answer may help you further with that part.
Here is the Windows port of pyenv, which is an excellent version management tool, which may also be of use.
Are you trying to create a virtual environment: by the looks of the path in the error - 'C:/Users/Tim-S/anaconda3/envs/plotlyenv/python.exe'
seems like you are trying to do so. IF that's the case:
Possible it did not get installed properly and hence cannot find the python file
you have to reinstall it and activate the environment
But that will solve the problem partially
After activating virtual environment, you have to install the library
that you are going to use
What I can see from your problem statement and file path you will need to install os and plotly
pip install os
pip install plotly - if required

django-admin command not regonized

I have installed django on my computer but when i try to run any django-admin command on my terminal i get this error:
django-admin : The term 'django-admin' 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
+ django-admin startproject app
+ CategoryInfo : ObjectNotFound: (django-admin:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I am using powershell and visual studio code
Is there any way i can fix this?
Django is a widely used framework, and it can be installed on multiple architectures and operating systems, now, understanding this premise, imagine that you are in front of the computer trying to answer the question you are asking.
For some collaborators it is really difficult or impossible to try to reproduce the error that is being presented to you without more details, my advice is to reformulate the question, for example:
I have an old computer running windows 10.
I installed the binary version for windows of python 3.7.
I installed pip, poetry, pipenv, and virtualenv to make a virtual environment.
I created the virtual environment with the following instruction .....
I installed django with the following statement ....
I am trying to create my project with this instruction ....
I get the following error message.
BTW, all the instructions I am executing from my PyCharm IDE .....
I recommend you read the following manual http://www.catb.org/~esr/faqs/smart-questions.html
I hope this can be of help to you so that you can provide more information and in this way receive a correct answer.

Python, Windows: The term 'conda' is not recognized as the name of a cmdlet

I am facing an issue with the Windows 10 Powershell. Whenever I open it I get an error:
& : The term 'C:\Users\hp\anaconda3\Scripts\conda.exe' 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 C:\Users\hp\Documents\WindowsPowerShell\profile.ps1:4 char:4
+ (& "C:\Users\hp\anaconda3\Scripts\conda.exe" "shell.powershell" "hook ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Users\hp\anaconda3\Scripts\conda.exe:String) [], CommandNotFoundExce
ption
+ FullyQualifiedErrorId : CommandNotFoundException
Previously I had installed anaconda and vs code to work in python but later I uninstalled anaconda and downloaded python3 from https://www.python.org/downloads/.
I have added the environment variables for Python in Path but still I get this error in the Powershell.
How to fix this?
Uninstall any other python interpreter installation and restart to refresh env variables
Download Anaconda Installer from here
You should add it to PATH if you want to use it outside of Anaconda Navigator and I recommend you install it systemwide with admin privilege
This should add conda executable to PATH allowing it to be called systemwide

How to modify Start Without Debugger script for python in MS Visual Studio Code

I recently installed MS Visual Studio Code for the first time (we'll be using it on an upcoming project). I wrote a simple Hello, World program in python and clicked Debug > Start Without Debugging. MSVSC runs the program just fine, but after that it runs a couple more commands, one of which generates an error (see below). These commands are unnecessary and the error is ugly and distracting.
Where is the script that MSVSC is running? I want to remove those two useless lines.
PS C:\Users\me> cd 'c:\Users\me\Documents\my-project'; ${env:PYTHONIOENCODING}='UTF-8'; ${env:PYTHONUNBUFFERED}='1'; & 'C:\Users\me\Anaconda3\python.exe' 'c:\Users\me\.vscode\extensions\ms-python.python-2019.4.12954\pythonFiles\ptvsd_launcher.py' '--default' '--nodebug' '--client' '--host' 'localhost' '--port' '51699' 'c:\Users\me\Documents\my-project\hello.py'
hello, world
distance 5.0
PS C:\Users\me\Documents\my-project> C:/Users/me/Anaconda3/Scripts/activate
PS C:\Users\me\Documents\my-project> conda activate base
conda : The term 'conda' 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
+ conda activate base
+ ~~~~~
+ CategoryInfo : ObjectNotFound: (conda:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS C:\Users\me\Documents\my-project>
They are not useless, you just happened to be running a file that happens to not need a specific conda environment activated. It's a general problem with conda that we're trying to solve. The smoothest experience would be to use virtual environments if that will work for you.

Categories

Resources