How can I rename a conda environment?

You can’t. One workaround is to create clone a new environment and then remove the original one. First, remember to deactivate your current environment. You can do this with the commands: deactivate on Windows or source deactivate on macOS/Linux. Then: Notice there are several drawbacks of this method: It redownloads packages (you can use –offline flag to disable it) Time consumed on copying … Read more

How to print a dictionary’s key?

A dictionary has, by definition, an arbitrary number of keys. There is no “the key”. You have the keys() method, which gives you a python list of all the keys, and you have the iteritems() method, which returns key-value pairs, so Python 3 version: So you have a handle on the keys, but they only really mean sense if coupled to … Read more

Implement touch using Python?

Looks like this is new as of Python 3.4 – pathlib. This will create a file.txt at the path. — Path.touch(mode=0o777, exist_ok=True) Create a file at this given path. If mode is given, it is combined with the process’ umask value to determine the file mode and access flags. If the file already exists, the function succeeds if … Read more

How to install multiple python packages at once using pip

For installing multiple packages on the command line, just pass them as a space-delimited list, e.g.: For installing from a text file, then, from pip install –help: -r FILENAME, –requirement=FILENAME Install all the packages listed in the given requirements file. This option can be used multiple times. Take a look at the pip documentation regarding requirements files for … Read more

Using Pip to install packages to Anaconda Environment

For others who run into this situation, I found this to be the most straightforward solution: Run conda create -n venv_name and conda activate venv_name, where venv_name is the name of your virtual environment. Run conda install pip. This will install pip to your venv directory. Find your anaconda directory, and find the actual venv folder. It should be somewhere like /anaconda/envs/venv_name/. … Read more

os.path.dirname(__file__) returns empty

Because os.path.abspath = os.path.dirname + os.path.basename does not hold. we rather have Both dirname() and basename() only split the passed filename into components without taking into account the current directory. If you want to also consider the current directory, you have to do so explicitly. To get the dirname of the absolute path, use