After "deactivate" from virtualvenv, prompt has "if defined _OLD_VIRTUAL_PYTHONPATH (set "PYTHONPATH=" ) " - virtualenv

I have a python (3.11) virtual env named "Test". Using VSC, Command "Workon Test" puts me in the Test virtual env. However, when I "deactivate", the command prompt has "if defined _OLD_VIRTUAL_PYTHONPATH (set "PYTHONPATH=" ) followed by the correct command prompt as expected (C:\Users\ksarn\ENVS>).
C:\Users\ksarn\ENVS>pip list
Package Version
--------------------- -------
distlib 0.3.6
filelock 3.8.0
pip 22.3.1
platformdirs 2.5.4
setuptools 65.5.0
virtualenv 20.16.7
virtualenvwrapper-win 1.2.7
C:\Users\ksarn\ENVS>workon test
(test) C:\Users\ksarn\ENVS>whereis python
C:\Users\ksarn\ENVS\test\Scripts\python.exe
(test) C:\Users\ksarn\ENVS>deactivate
C:\Users\ksarn\ENVS>if defined _OLD_VIRTUAL_PYTHONPATH (set "PYTHONPATH=" )
C:\Users\ksarn\ENVS>
C:\Users\ksarn\ENVS>whereis python
C:\Users\ksarn\AppData\Local\Programs\Python\Python311\python.exe
C:\Users\ksarn\ENVS>
Why is it showing set "Python path statement?
Re-installed python 3.11 (with path selected), virtualenv and virtualenvwrapper-win. No change.

I had the same problem. What worked for me in Windows is editing the routine that creates each environment.
Find and go the folder where default python is installed, which is used as base for virtualenv, e.g., C:\Users\<UserName>\AppData\Local\Programs\Python\Python311 (user only installation).
Secondary click > Edit on the file \Scripts\mkvirtualenv.bat
Search for "_OLD_VIRTUAL_PYTHONPATH" (about in the middle of the file) and write the # character to mute each command to be written in activate.bat and deactivate.bat. The result should look something like this:
:: In activate.bat, keep track of PYTHONPATH.
:: This should be a change adopted by virtualenv.
>>"%WORKON_HOME%\%venvwrapper.quoteless_envname%\Scripts\activate.bat" (
echo.:: In case user makes changes to PYTHONPATH
echo.#if defined _OLD_VIRTUAL_PYTHONPATH (
echo. #set "PYTHONPATH=%%_OLD_VIRTUAL_PYTHONPATH%%"
echo.^) else (
echo. #set "_OLD_VIRTUAL_PYTHONPATH=%%PYTHONPATH%%"
echo.^)
)
:: In deactivate.bat, reset PYTHONPATH to its former value
>>"%WORKON_HOME%\%venvwrapper.quoteless_envname%\Scripts\deactivate.bat" (
echo.
echo.#if defined _OLD_VIRTUAL_PYTHONPATH (
echo. #set "PYTHONPATH=%%_OLD_VIRTUAL_PYTHONPATH%%"
echo.^)
)
Save the file and re-create any environment tha had the problem. It shouldn't verbose any command.
As an alternative, you can edit directly edit the activate.bat and deactivate.bat files for each environment within its \Scripts\ subfolder.

Related

Powershell Pre-Build script failing from msbuild

I have a Powershell script that executes as a pre-build call for a Xamarin mobile app. The script changes the package name to match the build type e.g. Debug, Release.
To enable different "flavours" of the app to be created, I have written a batch file to replace the config file of the app with one matching the requested build type.
When I build from within Visual Studio, the powershell script runs as I expect and changes what I expected. However when the batch file runs I get an error message appearing:
Here is the content of the batch file, this was my first attempt at writing a batch file to build a code project:
#ECHO OFF
set buildVer=%1
set path=XamarinTestApp\XamarinTestApp
set msBuildDir=%WINDIR%\Microsoft.NET\Framework\v4.0.30319
echo %buildVer%
IF "%buildVer%"=="Release" (
goto :releaseBuild)
IF "%buildVer%"=="Test" (
goto :testBuild)
IF "%buildVer%"=="Dev" (
goto :devBuild)
:releaseBuild
set buildType=Release
copy /-y %path%\app.Release.config %path%\app.Config
goto :builder
:testBuild
set buildType=Release
copy /-y %path%\app.Test.config %path%\app.Config
goto :builder
:devBuild
set buildType=Debug
copy /-y %path%\app.Debug.config %path%\app.Config
goto :builder
:builder
call %msBuildDir%\msbuild.exe
C:\Projects\%path%\XamarinTestApp.Droid\XamarinTestApp.Droid.csproj /property:Configuration=%buildType% /target:SignAndroidPackage /verbosity:diag
I'm looking for any advice on either the error message I am getting, or some advice on how to get configurable information into my app.
Thanks.
Do not use path as user-variable. It is predefined by the system to locate executables.
Change that name to mypath - almost anything other than path.
from the prompt, use the command
set
to see a partial list of the names of variables that are set by the system

Calling Date Modified in CMD

Basically just attempting to create a very basic program that will display the last modified date of a file on our server. Problem is I have no idea how to write it. This is what I attempted
cd \\Server\Folder
msg dir
I also ran into the problem "CMD Does not support UNC Paths as Current Directories" when I tried to change the CD to our servers directory.
What I would like it to do is display in a dialog box the modified date of a "Text.txt" located on our server \\Server\Folder
Any and all help is appreciated
Next .bat script should work:
set "_folder=\\Server\Folder"
set "_filename=Text.txt"
set "_filedatetime=N/A"
pushd %_folder%
for %%G in (%_filename%) do (
rem echo %%~tG %%~fG
if not "%%~tG"=="" set "_filedatetime=%%~tG"
)
popd
echo file %_folder%\%_filename% date and time: %_filedatetime%
Note there is no dialog box in pure cmd command line interpreter, try set /P.
Resources:
SET: Display, set, or remove CMD environment variables
PUSHD, POPD: and UNC Network paths
FOR commands
~ Parameter Extensions

How does the "Eclipse IDE" manipulate Windows environment "Path" variable?

I have problems setting "run configuration" in Eclipse. When I use the Windows cmd to compile and run java.class I use .bat file that looks like this:
rem Wipe standard Windows Path variable and use this:
set PATH = C: \ Program Files \ .this path.;..and this one..;…;…
rem needed CLASSPATH's
set CLASSPATH = "... some \ path / *; ...
rem Path to native .dll libs
set LIB_PATH = "C: \ ... \ bin"
javac-cp% CLASSPATH% "... \ SomeExample.java"
java-cp% CLASSPATH%-Djava.library.path =% LIB_PATH% SomeExample
And everything works as it should, both compile and run are ok. When I try to do the same through Eclipse, by adjusting the classpath in run configuration GUI, compile is ok (I test it manualy in CMD), but during execution compiled class, I get java.lang. "UnsatisfiedLinkError ... someImportantDLL.dll: The specified procedure could not be found, " Which is the same error that I get while running in cmd if I do not set the PATH enviroment variable manually in .bat file!
What should I do in Eclipse to run properly compiled class?
Add the correct -Djava.library.path to the VM Arguments field. Don't rely on the external environment--you should control everything about your application's environment so you won't have any "gotchas" when you roll it out.

Windows Batch error: "'ping' is not recognized as an internal or external command operable program or batch file."

I am trying to run this command in windows:
ping -n 5 127.0.0.1 > nul
I get the error:
'ping' is not recognized as an internal or external command operable
program or batch fie.
Why can't windows find ping? Here is my script where it does not work:
#ECHO OFF
::set path
SET path=M:\\5.bmp
:findfile
IF EXIST %path% (
ECHO File found
) ELSE (
ECHO File not found
ping -n 5 127.0.0.1 > nul
goto findfile
)
You have overridden the PATH environment variable, so the command processor can no longer find the ping executable.
The fix is nice and simple - just use a different variable name!
:: set path
SET MyPath=M:\\5.bmp
:findfile
IF EXIST %MyPath% (
Please note that if you genuinely wanted to set the path environment variable, you should append to it like so:
REM Set temporarily for this session
SET PATH=%PATH%;C:\Some\Folder
REM Set permanently (but note - this change will not be made to this session)
SETX PATH=%PATH%;C:\Some\Folder
Hi to fix "ping" please follow below steps
Go to Properties in My computer
Advanced system settings ----->Advanced -----> Environment Variables
Select 'PATH' from the list of system variables and edit and set PATH to c:\windows\system32 ; this will solve your problem.
-----> if still u have a problem, do the below steps...
Control Panel --> System and security --> Windows Firewall --> Advanced settings --> Inbound rules --> New rule --> custom rule
in Protocol and ports: Protocol: ICMPv4
on the same panel go to customize, choose "Specific ICMP types", check the box "echo request"
The rest is trivial; go to next... next... and save it.
You should be done. This box responds ping from this point on.
Cheers
Prasad
How to diagnose this error:
'ping' is not recognized as an internal or external command operable
program or batch fie.
Because your path environment variable does not contain the directory that points to the executable: ping.exe. So the question becomes why can't your command line program cmd.exe locate ping.exe?
You can print out your path variable on the commandline like this:
echo %PATH%
Which prints for me:
C:\WINDOWS;C:\WINDOWS\system32;C:\Program Files\jZip;C:\MinGW\bin
The above string is delimited by semicolons(;). Notice the element called: C:\WINDOWS\System32, that is the element that defines where ping.exe can be located.
Solutions
You didn't specify C:\WINDOWS\System32 in your path variable. Make sure it is there.
ping.exe is missing. Find out who deleted it and put it back.
ping.exe is corrupt. Run it where it sits: C:\WINDOWS\System32\ping.exe, or replace ping.exe.
You have overridden the PATH variable before you look for it.

Tool for commandline "bookmarks" on windows?

Im searching a tool which allows me to specify some folders as "bookmarks" and than access them on the commandline (on Windows XP) via a keyword. Something like:
C:\> go home
D:\profiles\user\home\> go svn-project1
D:\projects\project1\svn\branch\src\>
I'm currently using a bunch of batch files, but editing them by hand is a daunting task. On Linux there is cdargs or shell bookmarks but I haven't found something on windows.
Thanks for the Powershell suggestion, but I'm not allowed to install it on my box at work, so it should be a "classic" cmd.exe solution.
What you are looking for is called DOSKEY
You can use the doskey command to create macros in the command interpreter. For example:
doskey mcd=mkdir "$*"$Tpushd "$*"
creates a new command "mcd" that creates a new directory and then changes to that directory (I prefer "pushd" to "cd" in this case because it lets me use "popd" later to go back to where I was before)
The $* will be replaced with the remainder of the command line after the macro, and the $T is used to delimit the two different commands that I want to evaluate. If I typed:
mcd foo/bar
at the command line, it would be equivalent to:
mkdir "foo/bar"&pushd "foo/bar"
The next step is to create a file that contains a set of macros which you can then import by using the /macrofile switch. I have a file (c:\tools\doskey.macros) which defines the commands that I regularly use. Each macro should be specified on a line with the same syntax as above.
But you don't want to have to manually import your macros every time you launch a new command interpreter, to make it happen automatically, just open up the registry key
HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun and set the value to be doskey /macrofile "c:\tools\doskey.macro". Doing this will make sure that your macros are automatically predefined every time you start a new interpreter.
Extra thoughts:
- If you want to do other things in AutoRun (like set environment parameters), you can delimit the commands with the ampersand. Mine looks like: set root=c:\SomeDir&doskey /macrofile "c:\tools\doskey.macros"
- If you prefer that your AutoRun settings be set per-user, you can use the HKCU node instead of HKLM.
- You can also use doskey to control things like the size of the command history.
- I like to end all of my navigation macros with \$* so that I can chain things together
- Be careful to add quotes as appropriate in your macros if you want to be able to handle paths with spaces in them.
I was looking for this exact functionality, for simple cases. Couldn't find a solution, so I made one myself:
#ECHO OFF
REM Source found on https://github.com/DieterDePaepe/windows-scripts
REM Please share any improvements made!
REM Folder where all links will end up
set WARP_REPO=%USERPROFILE%\.warp
IF [%1]==[/?] GOTO :help
IF [%1]==[--help] GOTO :help
IF [%1]==[/create] GOTO :create
IF [%1]==[/remove] GOTO :remove
IF [%1]==[/list] GOTO :list
set /p WARP_DIR=<%WARP_REPO%\%1
cd %WARP_DIR%
GOTO :end
:create
IF [%2]==[] (
ECHO Missing name for bookmark
GOTO :EOF
)
if not exist %WARP_REPO%\NUL mkdir %WARP_REPO%
ECHO %cd% > %WARP_REPO%\%2
ECHO Created bookmark "%2"
GOTO :end
:list
dir %WARP_REPO% /B
GOTO :end
:remove
IF [%2]==[] (
ECHO Missing name for bookmark
GOTO :EOF
)
if not exist %WARP_REPO%\%2 (
ECHO Bookmark does not exist: %2
GOTO :EOF
)
del %WARP_REPO%\%2
GOTO :end
:help
ECHO Create or navigate to folder bookmarks.
ECHO.
ECHO warp /? Display this help
ECHO warp [bookmark] Navigate to existing bookmark
ECHO warp /remove [bookmark] Remove an existing bookmark
ECHO warp /create [bookmark] Navigate to existing bookmark
ECHO warp /list List existing bookmarks
ECHO.
:end
You can list, create and delete bookmarks. The bookmarks are stored in text files in a folder in your user directory.
Usage (copied from current version):
A folder bookmarker for use in the terminal.
c:\Temp>warp /create temp # Create a new bookmark
Created bookmark "temp"
c:\Temp>cd c:\Users\Public # Go somewhere else
c:\Users\Public>warp temp # Go to the stored bookmark
c:\Temp>
Every warp uses a pushd command, so you can trace back your steps using popd.
c:\Users\Public>warp temp
c:\Temp>popd
c:\Users\Public>
Open a folder of a bookmark in explorer using warp /window <bookmark>.
List all available options using warp /?.
With just a Batch file, try this... (save as filename "go.bat")
#echo off
set BookMarkFolder=c:\data\cline\bookmarks\
if exist %BookMarkFolder%%1.lnk start %BookMarkFolder%%1.lnk
if exist %BookMarkFolder%%1.bat start %BookMarkFolder%%1.bat
if exist %BookMarkFolder%%1.vbs start %BookMarkFolder%%1.vbs
if exist %BookMarkFolder%%1.URL start %BookMarkFolder%%1.URL
Any shortcuts, batch files, VBS Scripts or Internet shortcuts you put in your bookmark folder (in this case "c:\data\cline\bookmarks\" can then be opened / accessed by typing "go bookmarkname"
e.g. I have a bookmark called "stack.url". Typing go stack takes me straight to this page.
You may also want to investigate Launchy
With PowerShell you could add the folders as variables in your profile.ps1 file, like:
$vids="C:\Users\mabster\Videos"
Then, like Unix, you can just refer to the variables in your commands:
cd $vids
Having a list of variable assignments in the one ps1 file is probably easier than maintaining separate batch files.
Another alternative approach you may want to consider could be to have a folder that contains symlinks to each of your projects or frequently-used directories. So you can do something like
cd \go\svn-project-1
cd \go\my-douments
Symlinks can be made on a NTFS disk using the Junction tool
Without Powershell you can do it like this:
C:\>set DOOMED=c:\windows
C:\>cd %DOOMED%
C:\WINDOWS>
Crono wrote:
Are Environment variables defined via "set" not meant for the current session only? Can I persist them?
They are set for the current process, and by default inherited by any process that it creates. They are not persisted to the registry. Their scope can be limited in cmd scripts with "setlocal" (and "endlocal").
Environment variables?
set home=D:\profiles\user\home
set svn-project1=D:\projects\project1\svn\branch\src
cd %home%
On Unix I use this along with popd/pushd/cd - all the time.