Incorrect Conda path after linux system migration - python

Our server was updated to use the NFS system, and the previous /scratch path is now mapped to /local/scratch. My anaconda3 was installed under /scratch/xxx/anaconda3, which basically means it is now under /local/scratch/xxx/anaconda3. Intuitively, I have updated the PATH variable in .bash_profile, and running which conda actually gives me
/local/scratch/xxx/anaconda3/bin/conda
However, when I actually tried to run $conda, the system reports the error below:
-bash: /scratch/xxx/anaconda3/bin/conda: No such file or directory
which is quite weird and indicates an inconsistency with the result returned by which conda.
In addition, I tried to directly cd into /local/scratch/xxx/anaconda3/bin/ and execute $./conda. It reports
-bash: ./conda: /scratch/xxx/anaconda3/bin/python: bad interpreter: No such file or directory
My wild guess is that in addition to the environment variable in .bash_profile, there are some internal settings of anaconda stored elsewhere, because the system actually knows the right path for python, while conda tries to execute python from the old path (i.e., /scratch/xxx/anaconda3/bin/python in the above error message). However, I couldn't seemingly find this file and change it to get things work.
Somehow, I feel this should be a common issue, however, I did not find any solutions from the internet. Any suggestions would be greatly appreciated.

I have fixed my issue using cpr (credits to #merv). Here I post the detailed instructions, so if some one has the same problem, he/she can almost just follow them to get things fixed.
1. Installation
According to anaconda.org, the recommended command to install cpr is
$ conda install -c anaconda conda-prefix-replacement
You may find this to be actually very awkward; the reason we need cpr is that our conda is broken due to the prefix issue, if we can run conda command to install cpr, then why should we need cpr?
Instead, we may install cpr directly from github:
$ git clone https://github.com/conda/conda-prefix-replacement.git
$ cd conda-prefix-replacement
$ python setup.py install
2. Rehome
After installation, running the rehome command to fix the prefix issue is quite straightforward. Say your anaconda is moving from path_A to path_B, simply do
$ cpr rehome path_B --old-prefix path_A
In my case, the command should be
$ cpr rehome /local/scratch/xxx/anaconda3 --old-prefix /scratch/xxx/anaconda3
After running the cpr command, exit the terminal and re-login. Everything should be good now!

Related

Problem running auto py to exe from terminal [duplicate]

I have python 3.9 I used the command 'pip install auto-py-to-exe' and it downloaded but when I tried to using the command 'auto-py-to-exe' the program just said " 'auto-py-to-exe' is not recognized as an internal or external command, operable program or batch file.". I have the latest version of PIP and I also have PATH. What can I do to fix this?
This works on VSCode:
python -m auto_py_to_exe
If I install "auto-py-to-exe" using following command, as described in this link as well as from the comment from Justin Ezequiel (above):
python -m pip install auto-py-to-exe
I am able to run it (in Windows 10) using following command:
python -m auto_py_to_exe
This gave me quite a bit of trouble, as none of the above solutions worked for me. Spent lots of time trying to figure out what I should be adding to PATH with no success.
My issue stemmed from (I think) the fact that I have been using python downloaded from the windows store, which uses a different location to store python in.
With the manual install of python (https://www.python.org) you can specify where python is downloaded and automatically add that location to path.
Steps I took to solve the problem:
Uninstall all versions of python downloaded from the windows store via settings (settings > apps > python > uninstall)
Uninstall all version of python via the control panel (control panel > add or remove programs > python x.x.x > uninstall)
Uninstall auto-py-to-exe (pip uninstall auto-py-to-exe) in case it didnt do that automatically
Install python from python.org. (auto-py-to-exe is not supported in versions greater than 3.10 as of 1/23/2023). So I installed Python 3.10
The settings which were successful for me were:
Custom installation,
check install python for all users,
check add to path,
input 'C:\Python310' (with the respective version number) for install location,
install
Check new python version has been installed python --version
Check pip is installed pip --version
Install auto-py-to-exe pip install auto-py-to-exe
When auto-py-to-exe finishes installing, scroll up through the install info and make sure there are no warnings that state there is a location not found in PATH. If there are, you'll have to do some other research on adding those locations to PATH appropriately (since I don't think I was doing that right).
Assuming no PATH warnings,
9. Run auto-py-to-exe
First you need to type in the terminal (not Python):
auto-py-to-exe
If you are currently in python use exit() to exit then try the above code.
It Depends on in which environment you have installed
Make sure to replace {User} with your user
In Conda Enviournment go to below location Manually
C:\Users\{User}\anaconda3\Scripts\auto-py-to-exe.exe
In Pip, Environment go to the location below
C:\Users\{User}\AppData\Local\Programs\Python\Python37-32\Scripts\auto-py-to-exe.exe
or you can add this path to your environment variable as well for accessing these from anywhere
First check you installed it
pip install auto-py-to-exe
then restart your vscode and check another time.
If still an error, check it in CMD.
As suggested above use:
pip show --files auto-py-to-exe to find out in what directory pip has
installed the scripts. Double check the directory is in %PATH%
This will show you where the installer has placed the binary files. I then changed to that directory which circumvents any path issue. I tried to run the files and found :
OSError: [WinError 1920] The file cannot be accessed by the system: 'C:\\Users\\aaaa\\AppData\\Local\\Microsoft\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\\python.exe'
PS C:\users\aaaa\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\Scripts>
In my case, although I haven't worked out how to fix it yet... It would seem to be trying to refer to an incorrect Python executable, the files in that directory are all 0 length. Unfortunately the "python -m" suggestion didn't work for me, so it's back to the drawing board. Hope that helps you confirm if it's the right solution to chase down.
You need to make sure you have typed cd C:\Users\your_user_name\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\Scripts as a separate command, and then auto-py-to-exe with python 3. Check in file explorer to make sure your path is correct if the cd fails.

Mac terminal, conda --version, 'command not found'

I am on a Mac. The terminal window doesn't seem to be able to access my bin or bash folder anymore, I'm not sure.
In the terminal window I am typing conda --version to determine which version of Anaconda I have installed but I get the message -bash: conda: command not found. - Also when I am in Atom, and am using the Python text editor and I'm trying to create a virtual environment, I type sudo conda create --name myDjangoEnv django and I get the same message, sudo: conda: command not found.
I used sudo because otherwise it would not let me set up a virtual environment without entering a password.
I think I edited the bash profile when I set up the virtual environment.
The thing is, I was able to do all of this yesterday, when I typed conda --version in my terminal I got the version of anaconda I installed, and I was able to update the version of anaconda. And in the python editor in Atom, when I typed sudo conda create --name myDjangoEnv django it set up a virtual environment. I was also able to update to the latest version of django.
Additionally, I had a new problem. In Atom I couldn't install a package. if I hit install a package, nothing would happen. Yesterday I was able to install packages. However I restarted Atom and now I am able to install packages, but I'm still having the problem listed above.
Does anyone know what is going on? I'm pretty new to all of this stuff. Should I reinstall Atom, Anaconda, django, and Python? Perhaps, I didn't install it to the right location? Is it easier to run all these programs on windows 10?
Atom is installed in /Users/myusername/Downloads
django: there's no .app for django so its hard to tell where its installed. Some of the folders for django are installed here:
/Users/myusername/newproject/newenv/lib/python3.7/site-packages
or another django folder's location is here:
/Users/myusername/opt/anaconda3/lib/python3.8/site-packages/bokeh/server
python: there are so many python folders, 1 python 3.8 folder's location is:
/Users/myusername/opt/anaconda3/pkgs/lxml-4.5.2-py38h63b7cb6_0/lib
Anaconda: /Users/myusername/opt/anaconda3
echo "$PATH" produces
/Volumes/myExternalDrive/opt/anaconda3/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
conda is installed in: /Users/myUserName/opt/anaconda3/pkgs/conda-4.8.3-py38_0/info/test/tests/test-recipes/activate_deactivate_package/src/etc –
Your PATH appears to have an incorrect component. Where you see
/Volumes/myExternalDrive/opt/anaconda3/bin
you should apparently have
/Users/myusername/opt/anaconda3/bin
At a terminal prompt, you can temporarily fix this with
PATH=/Users/myusername/opt/anaconda3/bin:$PATH
and at that point, you should be able to run conda --version and python3 in that terminal instance, until you terminate it.
The proper permanent fix is to find the place where this was incorrectly configured, and correct it there; probably your .bashrc needs a more thorough cleanup, but that's already far outside the scope of your original question.
(This assumes your home directory is /Users/myusername; the command echo "$HOME" should confirm this. That's where you'd look for .bashrc too.)

Confused about Python installations, module installation, and interpreter

So yesterday I had to create a virtualenv in order to be able to install Python modules that wouldn't install thanks to OS X El Capitan's new SIP. I thought I did everything right, but today I'm reaching a different conclusion. I hope I can be clear about it.
my python custom install is at myname/learnp/imdb_module, this is where I created it with virtualenv. Edit: I later moved it to myname/learnp/ayr2/imdb_module.
However, when I try to run the interpreter, it seems to always default to the Python that is in Library or something along these lines. I found out about this because a certain module that I managed to install in this custom python env wouldn't import, when I checked what modules I have, it wasn't the same as what I expected.
Furthermore, it seems that ALL other modules that I wanted to install on the CUSTOM virtualenv were installed on the main python env, and that I wasn't installing those modules on the custom env all along.
Excuse me, but I'm very confused right now.
I know how to create a virtual env
I know how to activate it (it appears to the right on Terminal line)
I don't know how to install modules to my virtual env
I don't know how to make the interpreter run from the virtual env so I can do python operations that are only possible by using custom env modules
Any advice is much appreciated!
Update:
Followed Will Hogan's answer for troubleshooting,and I think something weird is happening, quoting my comment to his answer:
HI, thanks for taking the time to answer. This is basically the way I understood this. However, let me attach a screenshot: http://i.imgur.com/DfpngJq.jpg . Am I right to assume something is wrong here? My prompt is changed with the virtualenv named "imdb_module", but when I type in which python it doesn't list ayr2/imdb_module/bin but rather a folder with the path usr/bin/python, which if I understand correctly is the "default" environment.
And not if this helps in any way, but echo $PATH when (imdv_module) appears to the right of the prompt, gives this (I redacted my name): /Users/REDACTEDNAME/learnp/imdb_module/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
While creating the virtualenv you should see it installing setuptools and pip:
$ virtualenv testvenv
New python executable in testvenv/bin/python2.7
Also creating executable in testvenv/bin/python
Installing setuptools, pip...done.
After ensuring the virtualenv is activated you should see your prompt change:
$ . ./testvenv/bin/activate
(testvenv)$
Now you can confirm the paths to python and pip, which should be in the virtualenv:
(testvenv)$ which python
/private/tmp/testvenv/bin/python
(testvenv)$ which pip
/private/tmp/testvenv/bin/pip
If you aren't seeing the python and pip locations as being under the virtualenv's directory, then the virtualenv has not been activated.
I would also ensure that, if you're executing the .py file directly (and not with "python foo.py"), that your shebang line uses:
#!/usr/bin/env python
Or even the full path to the virtualenv's python, e.g.:
#!/tmp/testvenv/bin/python
As opposed to, say:
#!/usr/bin/python
The first will search in the current environment, which will be set by the virtualenv activation. The second explicitly points to the virtualenv's `python'.

Using python virtualenv in mac OS X 10.6.8

I am learning Django (using version 1.4.5, bitnami stack) and Python (2.7.3) and trying to use virtualenv (version 1.8.4) for the first time. I have already installed virtualenv using pip and it seemed to install fine. However, when I try to create a new virtualenv environment, I seem to run into problems. Here's the errors I'm getting:
Attempt 1:
$ python virtualenv.py ENV
/Applications/djangostack-1.4.5-0/python/bin/.python2.7.bin: can't open file 'virtualenv.py'
[Errno 2] No such file or directory.
Attempt 2:
$ virtualenv venv --distribute
dyld: Library not loaded: /bitnami/djangostack-osx-x64/output/python/lib/libpython2.7.dylib
Referenced from: /Applications/djangostack-1.4.5-0/python/bin/.python2.7.bin
Reason: image not found
Trace/BPT trap
I searched for virtualenv.py and found that it is located at:
/Applications/djangostack-1.4.5-0/python/lib/python2.7/site-packages/
Attempt 3: I can cd to this folder from the command line and run the following command to create a new environment in the myproject_dir folder:
$ python virtualenv.py myproject_dir
Unlike Attempts 1 and 2, Attempt 3 actually seems to work, but it is not optimal. So, my conclusion is that somehow for the commands in Attempts 1 and 2, the system is looking in the wrong place. My sense is that a setting needs to be changed somewhere to point to the correct location of the virtualenv.py file, but I'm not sure where to look and how to actually make the changes? I've looked at other explanations on this site and Google, but still am not sure whether my diagnosis of the problem is correct and how to actually fix the problem.
Attempt one, don't do that, do this:
virtualenv ENV
attempt two indicates that you have your python paths muddled up as #Thai Trans says. I would make sure that you're calling the correct python from virtualenv
virtualenv -p /path/to/bitnami/python ENV
and not worry about the --distribute flag until you've got your regular virtualenv working.

Django installation - virtualenv.py errors out

I am trying to create a Virtual Environment for my django site.
Command is below. but it says "You must provide a DEST_DIR" though I have given the directory name "SOWL".
virtualenv.py SOWL --no-site-packages
http://screencast.com/t/rej893zrg
I have spent half a day on this. I can't find anything on google search either.
Any help is much appreciated.
Thanks,
SHM
At first glance your command is out of order; the flags come first, directory last. However it doesn't seem to matter; the command, as you ran it, works for me on Mac and Windows.
I'd guess the problem lies with your installation of virtualenv. Virtualenv is also one of those tools that never seems to get updated. Make sure you have the latest. Install with pip (first choice) or if you need the actual virtualenv.py file, either way the instructions are here.
UPDATE Here's an install-Python-in-Windows guide. I know you already have Python, but this will make sure your PATH is setup and get you PIP and Virtualenv as well.
Install Python using the Windows installer
Add this to your PATH environment variable: C:\Python27\;C:\Python27\Scripts\
Get Distribute by downloading the distribute_setup.py file. (There is no Windows installer; the script does it all.)
Get PIP by downloading the get-pip.py file.
python distribute_setup.py
python get-pip.py
pip install virtualenv
Now you are set with virtualenv. However there's more — the virtualenvwrapper makes life easy. It's only for bash shells, but there's a Windows port here. There are installation instructions, tips and a rundown of the nifty new commands that the wrapper gives you.
pip install virtualenvwrapper-win
pyassoc
Create a new environment variable: WORKON_HOME=%USERPROFILE%\Envs
Now you can do this to create your virtualenv (and notice the prompt change to indicate which env you are in):
mkvirtualenv --distribute SOWL
>>>(SOWL) C:\Users\User>
I think your parameters are just out of order. Did you try
virtualenv.py --no-site-packages SOWL

Categories