$ conda create --name 3point6 python=3.6Fetching package metadata .......Solving package specifications:..........Package plan for installation in environment /Users/dstansby/miniconda3/envs/3point6:The following NEW packages will be INSTALLED:
openssl:1.0.2j-0
pip:9.0.1-py36_1
python:3.6.0-0
readline:6.2-2
setuptools:27.2.0-py36_0
sqlite:3.13.0-0
tk:8.5.18-0
wheel:0.29.0-py36_0
xz:5.2.2-1
zlib:1.2.8-3
I also had to conda remove some packages not on the official list:
backports_abc
beautiful-soup
blaze-core
Depending on packages installed on your system, you may get additional UnsatisfiableError errors – simply add those packages to the remove list. Next, install the version of Python,
conda install python==3.6
which takes a while, after which a message indicated to conda install anaconda-client, so I did
conda install anaconda-client
which said it’s already there. Finally, following the directions,
conda update anaconda
I did this in the Windows 10 command prompt, but things should be similar in Mac OS X.
In the past, I have found it quite difficult to try to upgrade in-place.
Note: my use-case for Anaconda is as an all-in-one Python environment. I don’t bother with separate virtual environments. If you’re using conda to create environments, this may be destructive because conda creates environments with hard-links inside your Anaconda/envs directory.
So if you use environments, you may first want to export your environments. After activating your environment, do something like:
conda env export > environment.yml
After backing up your environments (if necessary), you may remove your old Anaconda (it’s very simple to uninstall Anaconda):
$ rm -rf ~/anaconda3/
and replace it by downloading the new Anaconda, e.g. Linux, 64 bit:
$ cd ~/Downloads
$ wget https://repo.continuum.io/archive/Anaconda3-4.3.0-Linux-x86_64.sh
with open('old_env.yml','r')as fin, open('new_env.yml','w')as fout:for line in fin:if'py35'in line:# replace by the version you want to supersede
line = line[:line.rfind('=')]+'\n'
fout.write(line)
with open('old_env.yml', 'r') as fin, open('new_env.yml', 'w') as fout:
for line in fin:
if 'py35' in line: # replace by the version you want to supersede
line = line[:line.rfind('=')] + '\n'
fout.write(line)
then edit manually the first (name: ...) and last line (prefix: ...) to reflect your new environment name and run:
conda env create -f new_env.yml
you might need to remove or change manually the version pin of a few packages for which which the pinned version from old_env is found incompatible or missing for the new python version.
I’m relatively new in Mac OS. I’ve just installed XCode (for c++ compiler) and Anaconda with the latest Python 3 (for myself). Now I’m wondering how to install properly second Anaconda (for work) with Python 2?
I need both versions to work with iPython and Spyder IDE. Ideal way is to have totally separate Python environments. For example, I wish I could write like conda install scikit-learn for Python 3 environment and something like conda2 install scikit-learn for Python 2.
There is no need to install Anaconda again. Conda, the package manager for Anaconda, fully supports separated environments. The easiest way to create an environment for Python 2.7 is to do
conda create -n python2 python=2.7 anaconda
This will create an environment named python2 that contains the Python 2.7 version of Anaconda. You can activate this environment with
source activate python2
This will put that environment (typically ~/anaconda/envs/python2) in front in your PATH, so that when you type python at the terminal it will load the Python from that environment.
If you don’t want all of Anaconda, you can replace anaconda in the command above with whatever packages you want. You can use conda to install packages in that environment later, either by using the -n python2 flag to conda, or by activating the environment.
Then before use Spyder you can choose Python environment like below!
Sometimes only you can see root and your new Python environment, so root is your first anaconda environment!
Also this is Jupyter. You can choose python version like this!
How can I completely uninstall Anaconda from MacOS Sierra and revert back to the original Python? I have tried using conda-clean -yes but that doesn’t work. I also remove the stuff in ~/.bash_profile but it still uses the Anaconda python and I can still run the conda command.
Once the configs are removed you can delete the anaconda install folder, which is usually under your home dir:
rm -rf ~/anaconda3
Also, the anaconda-clean --yes command creates a backup in your home directory of the format ~/.anaconda_backup/<timestamp>. Make sure to delete that one also.
EDIT (v5.2.0): Now if you want to clean all, you will also have to delete the two last lines added to your .bash_profile. They look like:
# added by Anaconda3 5.2.0 installer
export PATH="/Users/ody/anaconda3/bin:$PATH"
Open the terminal and remove your entire Anaconda directory, which will have a name such as “anaconda2” or “anaconda3”, by entering the following command: rm -rf ~/anaconda3. Then remove conda with command “conda uninstall” https://conda.io/docs/commands/conda-uninstall.html.
After performing the very helpful suggestions from both spicyramen & jkysam without immediate success, a simple restart of my Mac was needed to make the system recognize the changes. Hope this helps someone!
Adding export PATH="/Users/<username>/anaconda/bin:$PATH" (or export PATH="/Users/<username>/anaconda3/bin:$PATH" if you have anaconda 3)
to my ~/.bash_profile file, fixed this issue for me.
but if you like me that didn’t work for some reason and for some reason your conda was installed somewhere else with telling you do this:
rm -rf ~/opt
I have no idea why it was saved there but that’s what did it for me.
This was useful to me in fixing my conda installation (if that is the reason you are uninstalling it in the first place like me): https://stackoverflow.com/a/60902863/1601580 that ended up fixing it for me. Not sure why conda was acting weird in the first place or installing things wrongly in the first place though…
How can a pre-existing conda environment be updated with another .yml file. This is extremely helpful when working on projects that have multiple requirement files, i.e. base.yml, local.yml, production.yml, etc.
For example, below is a base.yml file has conda-forge, conda, and pip packages:
The suggested answer is partially correct. You’ll need to add the –prune option to also uninstall packages that were removed from the environment.yml.
Correct command:
alkamid’s answer is on the right lines, but I have found that Conda fails to install new dependencies if the environment is already active. Deactivating the environment first resolves this:
source deactivate;
conda env update -f whatever.yml;
source activate my_environment_name; # Must be AFTER the conda env update line!
I have a machine learning classification problem with 80% categorical variables. Must I use one hot encoding if I want to use some classifier for the classification? Can i pass the data to a classifier without the encoding?
I am trying to do the following for feature selection:
I change the type of the categorical features to ‘category’:
non_categorial_features = ['orig_destination_distance',
'srch_adults_cnt',
'srch_children_cnt',
'srch_rm_cnt',
'cnt']
for categorical_feature in list(train_small.columns):
if categorical_feature not in non_categorial_features:
train_small[categorical_feature] = train_small[categorical_feature].astype('category')
The problem is that the 3’rd part often get stuck, although I am using a strong machine.
Thus, without the one hot encoding I can’t do any feature selection, for determining the importance of the features.
What do you recommend?
回答 0
方法1:您可以在pandas数据框上使用get_dummies。
范例1:
import pandas as pd
s = pd.Series(list('abca'))
pd.get_dummies(s)Out[]:
a b c01.00.00.010.01.00.020.00.01.031.00.00.0
范例2:
下面将把给定的列转换为一个热门列。使用前缀具有多个虚拟变量。
import pandas as pd
df = pd.DataFrame({'A':['a','b','a'],'B':['b','a','c']})
dfOut[]:
A B0 a b1 b a2 a c# Get one hot encoding of columns B
one_hot = pd.get_dummies(df['B'])# Drop column B as it is now encoded
df = df.drop('B',axis =1)# Join the encoded df
df = df.join(one_hot)
df Out[]:
A a b c0 a 0101 b 1002 a 001
import pandas as pd
s = pd.Series(list('abca'))
pd.get_dummies(s)
Out[]:
a b c
0 1.0 0.0 0.0
1 0.0 1.0 0.0
2 0.0 0.0 1.0
3 1.0 0.0 0.0
Example 2:
The following will transform a given column into one hot. Use prefix to have multiple dummies.
import pandas as pd
df = pd.DataFrame({
'A':['a','b','a'],
'B':['b','a','c']
})
df
Out[]:
A B
0 a b
1 b a
2 a c
# Get one hot encoding of columns B
one_hot = pd.get_dummies(df['B'])
# Drop column B as it is now encoded
df = df.drop('B',axis = 1)
# Join the encoded df
df = df.join(one_hot)
df
Out[]:
A a b c
0 a 0 1 0
1 b 1 0 0
2 a 0 0 1
Approach 2: Use Scikit-learn
Using a OneHotEncoder has the advantage of being able to fit on some training data and then transform on some other data using the same instance. We also have handle_unknown to further control what the encoder does with unseen data.
Given a dataset with three features and four samples, we let the encoder find the maximum value per feature and transform the data to a binary one-hot encoding.
Much easier to use Pandas for basic one-hot encoding. If you’re looking for more options you can use scikit-learn.
For basic one-hot encoding with Pandas you pass your data frame into the get_dummies function.
For example, if I have a dataframe called imdb_movies:
…and I want to one-hot encode the Rated column, I do this:
pd.get_dummies(imdb_movies.Rated)
This returns a new dataframe with a column for every “level” of rating that exists, along with either a 1 or 0 specifying the presence of that rating for a given observation.
Usually, we want this to be part of the original dataframe. In this case, we attach our new dummy coded frame onto the original frame using “column-binding.
We can column-bind by using Pandas concat function:
import numpy as np
nb_classes =6
data =[[2,3,4,0]]def indices_to_one_hot(data, nb_classes):"""Convert an iterable of indices to one-hot encoded labels."""
targets = np.array(data).reshape(-1)return np.eye(nb_classes)[targets]
You can do it with numpy.eye and a using the array element selection mechanism:
import numpy as np
nb_classes = 6
data = [[2, 3, 4, 0]]
def indices_to_one_hot(data, nb_classes):
"""Convert an iterable of indices to one-hot encoded labels."""
targets = np.array(data).reshape(-1)
return np.eye(nb_classes)[targets]
The the return value of indices_to_one_hot(nb_classes, data) is now
from sklearn.preprocessing importLabelEncoder#Auto encodes any dataframe column of type category or object.def dummyEncode(df):
columnsToEncode = list(df.select_dtypes(include=['category','object']))
le =LabelEncoder()for feature in columnsToEncode:try:
df[feature]= le.fit_transform(df[feature])except:print('Error encoding '+feature)return df
编辑:比较要更清楚:
一键编码:将n个级别转换为n-1列。
IndexAnimalIndex cat mouse
1 dog 1002 cat -->2103 mouse 301
如果分类功能中有许多不同的类型(或级别),则可以看到这将如何扩展您的内存。请记住,这只是一栏。
虚拟编码:
IndexAnimalIndexAnimal1 dog 102 cat -->213 mouse 32
Lastly, is it necessary for you to one hot encode? One hot encoding exponentially increases the number of features, drastically increasing the run time of any classifier or anything else you are going to run. Especially when each categorical feature has many levels. Instead you can do dummy coding.
Using dummy encoding usually works well, for much less run time and complexity. A wise prof once told me, ‘Less is More’.
Here’s the code for my custom encoding function if you want.
from sklearn.preprocessing import LabelEncoder
#Auto encodes any dataframe column of type category or object.
def dummyEncode(df):
columnsToEncode = list(df.select_dtypes(include=['category','object']))
le = LabelEncoder()
for feature in columnsToEncode:
try:
df[feature] = le.fit_transform(df[feature])
except:
print('Error encoding '+feature)
return df
EDIT: Comparison to be clearer:
One-hot encoding: convert n levels to n-1 columns.
Index Animal Index cat mouse
1 dog 1 0 0
2 cat --> 2 1 0
3 mouse 3 0 1
You can see how this will explode your memory if you have many different types (or levels) in your categorical feature. Keep in mind, this is just ONE column.
Dummy Coding:
Index Animal Index Animal
1 dog 1 0
2 cat --> 2 1
3 mouse 3 2
Convert to numerical representations instead. Greatly saves feature space, at the cost of a bit of accuracy.
回答 4
使用熊猫进行热编码非常简单:
def one_hot(df, cols):"""
@param df pandas DataFrame
@param cols a list of columns to encode
@return a DataFrame with one-hot encoding
"""for each in cols:
dummies = pd.get_dummies(df[each], prefix=each, drop_first=False)
df = pd.concat([df, dummies], axis=1)return df
编辑:
使用sklearn的另一种方式one_hot LabelBinarizer:
from sklearn.preprocessing importLabelBinarizer
label_binarizer =LabelBinarizer()
label_binarizer.fit(all_your_labels_list)# need to be global or remembered to use it laterdef one_hot_encode(x):"""
One hot encode a list of sample labels. Return a one-hot encoded vector for each label.
: x: List of sample Labels
: return: Numpy array of one-hot encoded labels
"""return label_binarizer.transform(x)
def one_hot(df, cols):
"""
@param df pandas DataFrame
@param cols a list of columns to encode
@return a DataFrame with one-hot encoding
"""
for each in cols:
dummies = pd.get_dummies(df[each], prefix=each, drop_first=False)
df = pd.concat([df, dummies], axis=1)
return df
EDIT:
Another way to one_hot using sklearn’s LabelBinarizer :
from sklearn.preprocessing import LabelBinarizer
label_binarizer = LabelBinarizer()
label_binarizer.fit(all_your_labels_list) # need to be global or remembered to use it later
def one_hot_encode(x):
"""
One hot encode a list of sample labels. Return a one-hot encoded vector for each label.
: x: List of sample Labels
: return: Numpy array of one-hot encoded labels
"""
return label_binarizer.transform(x)
回答 5
您可以使用numpy.eye函数。
import numpy as np
def one_hot_encode(x, n_classes):"""
One hot encode a list of sample labels. Return a one-hot encoded vector for each label.
: x: List of sample Labels
: return: Numpy array of one-hot encoded labels
"""return np.eye(n_classes)[x]def main():
list =[0,1,2,3,4,3,2,1,0]
n_classes =5
one_hot_list = one_hot_encode(list, n_classes)print(one_hot_list)if __name__ =="__main__":
main()
import numpy as np
def one_hot_encode(x, n_classes):
"""
One hot encode a list of sample labels. Return a one-hot encoded vector for each label.
: x: List of sample Labels
: return: Numpy array of one-hot encoded labels
"""
return np.eye(n_classes)[x]
def main():
list = [0,1,2,3,4,3,2,1,0]
n_classes = 5
one_hot_list = one_hot_encode(list, n_classes)
print(one_hot_list)
if __name__ == "__main__":
main()
One-hot encoding requires bit more than converting the values to indicator variables. Typically ML process requires you to apply this coding several times to validation or test data sets and applying the model you construct to real-time observed data. You should store the mapping (transform) that was used to construct the model. A good solution would use the DictVectorizer or LabelEncoder (followed by get_dummies. Here is a function that you can use:
This works on a pandas dataframe and for each column of the dataframe it creates and returns a mapping back. So you would call it like this:
train_data, le_dict = oneHotEncode2(train_data)
Then on the test data, the call is made by passing the dictionary returned back from training:
test_data, _ = oneHotEncode2(test_data, le_dict)
An equivalent method is to use DictVectorizer. A related post on the same is on my blog. I mention it here since it provides some reasoning behind this approach over simply using get_dummies post (disclosure: this is my own blog).
You can pass the data to catboost classifier without encoding. Catboost handles categorical variables itself by performing one-hot and target expanding mean encoding.
回答 10
您也可以执行以下操作。请注意以下内容,您不必使用pd.concat。
import pandas as pd
# intialise data of lists.
data ={'Color':['Red','Yellow','Red','Yellow'],'Length':[20.1,21.1,19.1,18.1],'Group':[1,2,1,2]}# Create DataFrame
df = pd.DataFrame(data)for _c in df.select_dtypes(include=['object']).columns:print(_c)
df[_c]= pd.Categorical(df[_c])
df_transformed = pd.get_dummies(df)
df_transformed
您还可以将显式列更改为分类。例如,在这里我要更改Color和Group
import pandas as pd
# intialise data of lists.
data ={'Color':['Red','Yellow','Red','Yellow'],'Length':[20.1,21.1,19.1,18.1],'Group':[1,2,1,2]}# Create DataFrame
df = pd.DataFrame(data)
columns_to_change = list(df.select_dtypes(include=['object']).columns)
columns_to_change.append('Group')for _c in columns_to_change:print(_c)
df[_c]= pd.Categorical(df[_c])
df_transformed = pd.get_dummies(df)
df_transformed
classOneHotEncoder:def __init__(self,optionKeys):
length=len(optionKeys)
self.__dict__={optionKeys[j]:[0if i!=j else1for i in range(length)]for j in range(length)}
class OneHotEncoder:
def __init__(self,optionKeys):
length=len(optionKeys)
self.__dict__={optionKeys[j]:[0 if i!=j else 1 for i in range(length)] for j in range(length)}
def one_hot_encode(y):"""Convert an iterable of indices to one-hot encoded labels."""
y = y.flatten()# Sometimes not flattened vector is passed e.g (118,1) in these cases# the function ends up creating a tensor e.g. (118, 2, 1). flatten removes this issue
nb_classes = len(np.unique(y))# get the number of unique classes
standardised_labels = dict(zip(np.unique(y), np.arange(nb_classes)))# get the class labels as a dictionary# which then is standardised. E.g imagine class labels are (4,7,9) if a vector of y containing 4,7 and 9 is# directly passed then np.eye(nb_classes)[4] or 7,9 throws an out of index error.# standardised labels fixes this issue by returning a dictionary;# standardised_labels = {4:0, 7:1, 9:2}. The values of the dictionary are mapped to keys in y array.# standardised_labels also removes the error that is raised if the labels are floats. E.g. 1.0; element# cannot be called by an integer index e.g y[1.0] - throws an index error.
targets = np.vectorize(standardised_labels.get)(y)# map the dictionary values to array.return np.eye(nb_classes)[targets]
def one_hot_encode(y):
"""Convert an iterable of indices to one-hot encoded labels."""
y = y.flatten() # Sometimes not flattened vector is passed e.g (118,1) in these cases
# the function ends up creating a tensor e.g. (118, 2, 1). flatten removes this issue
nb_classes = len(np.unique(y)) # get the number of unique classes
standardised_labels = dict(zip(np.unique(y), np.arange(nb_classes))) # get the class labels as a dictionary
# which then is standardised. E.g imagine class labels are (4,7,9) if a vector of y containing 4,7 and 9 is
# directly passed then np.eye(nb_classes)[4] or 7,9 throws an out of index error.
# standardised labels fixes this issue by returning a dictionary;
# standardised_labels = {4:0, 7:1, 9:2}. The values of the dictionary are mapped to keys in y array.
# standardised_labels also removes the error that is raised if the labels are floats. E.g. 1.0; element
# cannot be called by an integer index e.g y[1.0] - throws an index error.
targets = np.vectorize(standardised_labels.get)(y) # map the dictionary values to array.
return np.eye(nb_classes)[targets]
import typing
def one_hot_encode(items: list)-> typing.List[list]:
results =[]# find the unique items (we want to unique items b/c duplicate items will have the same encoding)
unique_items = list(set(items))# sort the unique items
sorted_items = sorted(unique_items)# find how long the list of each item should be
max_index = len(unique_items)for item in items:# create a list of zeros the appropriate length
one_hot_encoded_result =[0for i in range(0, max_index)]# find the index of the item
one_hot_index = sorted_items.index(item)# change the zero at the index from the previous line to a one
one_hot_encoded_result[one_hot_index]=1# add the result
results.append(one_hot_encoded_result)return results
Here is a function to do one-hot-encoding without using numpy, pandas, or other packages. It takes a list of integers, booleans, or strings (and perhaps other types too).
import typing
def one_hot_encode(items: list) -> typing.List[list]:
results = []
# find the unique items (we want to unique items b/c duplicate items will have the same encoding)
unique_items = list(set(items))
# sort the unique items
sorted_items = sorted(unique_items)
# find how long the list of each item should be
max_index = len(unique_items)
for item in items:
# create a list of zeros the appropriate length
one_hot_encoded_result = [0 for i in range(0, max_index)]
# find the index of the item
one_hot_index = sorted_items.index(item)
# change the zero at the index from the previous line to a one
one_hot_encoded_result[one_hot_index] = 1
# add the result
results.append(one_hot_encoded_result)
return results
I know there are already a lot of answers to this question, but I noticed two things. First, most of the answers use packages like numpy and/or pandas. And this is a good thing. If you are writing production code, you should probably be using robust, fast algorithms like those provided in the numpy/pandas packages. But, for the sake of education, I think someone should provide an answer which has a transparent algorithm and not just an implementation of someone else’s algorithm. Second, I noticed that many of the answers do not provide a robust implementation of one-hot encoding because they do not meet one of the requirements below. Below are some of the requirements (as I see them) for a useful, accurate, and robust one-hot encoding function:
A one-hot encoding function must:
handle list of various types (e.g. integers, strings, floats, etc.) as input
handle an input list with duplicates
return a list of lists corresponding (in the same order as) to the inputs
return a list of lists where each list is as short as possible
I tested many of the answers to this question and most of them fail on one of the requirements above.
回答 18
试试这个:
!pip install category_encoders
import category_encoders as ce
categorical_columns =[...the list of names of the columns you want to one-hot-encode ...]
encoder = ce.OneHotEncoder(cols=categorical_columns, use_cat_names=True)
df_train_encoded = encoder.fit_transform(df_train_small)
!pip install category_encoders
import category_encoders as ce
categorical_columns = [...the list of names of the columns you want to one-hot-encode ...]
encoder = ce.OneHotEncoder(cols=categorical_columns, use_cat_names=True)
df_train_encoded = encoder.fit_transform(df_train_small)
df_encoded.head()
The resulting dataframe df_train_encoded is the same as the original, but the categorical features are now replaced with their one-hot-encoded versions.
For the case that you wish to revert a recently installed package that made several changes to dependencies (such as tensorflow), you can “roll back” to an earlier installation state via the following method:
conda list --revisions
conda install --revision [revision number]
The first command shows previous installation revisions (with dependencies) and the second reverts to whichever revision number you specify.
Note that if you wish to (re)install a later revision, you may have to sequentially reinstall all intermediate versions. If you had been at revision 23, reinstalled revision 20 and wish to return, you may have to run each:
How can I make anaconda environment file which could be use on other computers?
I exported my anaconda python environment to YML using conda env export > environment.yml. The exported environment.yml contains this line prefix: /home/superdev/miniconda3/envs/juicyenv which maps to my anaconda’s location which will be different on other’s pcs.
I can’t find anything in the conda specs which allow you to export an environment file without the prefix: ... line. However, as Alex pointed out in the comments, conda doesn’t seem to care about the prefix line when creating an environment from file.
With that in mind, if you want the other user to have no knowledge of your default install path, you can remove the prefix line with grep before writing to environment.yml.
and the environment will get installed in their default conda environment path.
If you want to specify a different install path than the default for your system (not related to ‘prefix’ in the environment.yml), just use the -p flag followed by the required path.
Note that Conda recommends creating the environment.yml by hand, which is especially important if you are wanting to share your environment across platforms (Windows/Linux/Mac). In this case, you can just leave out the prefix line.
I find exporting the packages in string format only is more portable than exporting the whole conda environment. As the previous answer already suggested:
$ conda list -e > requirements.txt
However, this requirements.txt contains build numbers which are not portable between operating systems, e.g. between Mac and Ubuntu. In conda env export we have the option --no-builds but not with conda list -e, so we can remove the build number by issuing the following command:
$ sed -i -E "s/^(.*\=.*)(\=.*)/\1/" requirements.txt
Conda and conda-forge are both Python package managers. What is the appropriate choice when a package exists in both repositories? Django, for example, can be installed with either, but the difference between the two is several dependencies (conda-forge has many more). There is no explanation for these differences, not even a simple README.
Which one should be used? Conda or conda-forge? Does it matter?
The short answer is that, in my experience generally, it doesn’t matter which you use.
The long answer:
So conda-forge is an additional channel from which packages may be installed. In this sense, it is not any more special than the default channel, or any of the other hundreds (thousands?) of channels that people have posted packages to. You can add your own channel if you sign up at https://anaconda.org and upload your own Conda packages.
Here we need to make the distinction, which I think you’re not clear about from your phrasing in the question, between conda, the cross-platform package manager, and conda-forge, the package channel. Anaconda Inc. (formerly Continuum IO), the main developers of the conda software, also maintain a separate channel of packages, which is the default when you type conda install packagename without changing any options.
There are three ways to change the options for channels. The first two are done every time you install a package and the last one is persistent. The first one is to specify a channel every time you install a package:
conda install -c some-channel packagename
Of course, the package has to exist on that channel. This way will install packagename and all its dependencies from some-channel. Alternately, you can specify:
conda install some-channel::packagename
The package still has to exist on some-channel, but now, only packagename will be pulled from some-channel. Any other packages that are needed to satisfy dependencies will be searched for from your default list of channels.
To see your channel configuration, you can write:
conda config --show channels
You can control the order that channels are searched with conda config. You can write:
conda config --add channels some-channel
to add the channel some-channel to the top of the channels configuration list. This gives some-channel the highest priority. Priority determines (in part) which channel is selected when more than one channel has a particular package. To add the channel to the end of the list and give it the lowest priority, type
conda config --append channels some-channel
If you would like to remove the channel that you added, you can do so by writing
conda config --remove channels some-channel
See
conda config -h
for more options.
With all of that said, there are four main reasons to use the conda-forge channel instead of the defaults channel maintained by Anaconda:
Packages on conda-forgemay be more up-to-date than those on the defaults channel
There are packages on the conda-forge channel that aren’t available from defaults
You would prefer to use a dependency such as openblas (from conda-forge) instead of mkl (from defaults).
If you are installing a package that requires a compiled library (e.g., a C extension or a wrapper around a C library), it may reduce the chance of incompatibilities if you install all of the packages in an environment from a single channel due to binary compatibility of the base C library (but this advice may be out of date/change in the future).
There are some Python libraries that you cannot install with a simple conda install since their channel is not available unless you apply conda-forge. From my experience, pip is more generic to look into different channel sources than conda.
For instance, if you want to install python-constraint you can do it via pip install but to install it via **cond **. you have to specify the channel – conda-forge.
conda install -c conda-forge python-constraint // works
I first installed Anaconda on my ubuntu at ~/anaconda, when I was trying to update my anaconda, according to the documentation from Continuum Analytics, I should use the following commands:
conda update conda
conda update anaconda
Then I realized that I did not have conda installed, so I installed it using the documentation from here.
After conda is installed, when I run conda update anaconda, I got the following error:
Error: package ‘anaconda’ is not installed in /home/xiang/miniconda
It appears conda is assuming my anaconda is installed under /home/xiang/miniconda which is NOT true.
The questions:
What are the differences between conda and anaconda?
How can I tell conda where my anaconda is installed?
conda is an environment manager and a package manager. It means the tool itself. conda makes it possible to
install package with conda install flake8
create an environment with any version of Python with conda create -n myenv python=3.6
conda is not a binary command, is a Python package. To make conda work, you have to create a Python environment and install package conda into it. This is where Anaconda installer and Miniconda installer comes in.
Installer Minoconda installs a Python and the package conda. Installer Anaconda not only does what Miniconda does, it also install a meta Python package named anaconda for you.
Meta packages, are packages that do NOT contain actual softwares and simply depend on other packages to be installed.
The actual 160+ python packages included in pkg anaconda are listed in info/recipe/meta.yaml in its source file.
我在Windows 7 Professional计算机上安装了Anaconda3 4.4.0(32位),并在Jupyter笔记本电脑上导入了NumPy和Pandas,因此我认为Python已正确安装。但是当我键入conda list并conda --version在命令提示符下时,它说conda is not recognized as internal or external command.
I installed Anaconda3 4.4.0 (32 bit) on my Windows 7 Professional machine and imported NumPy and Pandas on Jupyter notebook so I assume Python was installed correctly. But when I type conda list and conda --version in command prompt, it says conda is not recognized as internal or external command.
I have set environment variable for Anaconda3; Variable Name: Path, Variable Value: C:\Users\dipanwita.neogy\Anaconda3
On Windows, the PATH environment variable is no longer changed by default, as this can cause trouble with other software. The recommended approach is to instead use Anaconda Navigator or the Anaconda Command Prompt (located in the Start Menu under “Anaconda”) when you wish to use Anaconda software.
(Note: recent Win 10 does not assume you have privileges to install or update. If the command fails, right-click on the Anaconda Command Prompt, choose “More”, chose “Run as administrator”)
This is a change from previous installations. It is suggested to use Navigator or the Anaconda Prompt although you can always add it to your PATH as well. During the install the box to add Anaconda to the PATH is now unchecked but you can select it.
When you install anaconda on windows now, it doesn’t automatically add Python or Conda to your path.
While during the installation process you can check this box, you can also add python and/or python to your path manually (as you can see below the image)
If you don’t know where your conda and/or python is, you type the following commands into your anaconda prompt
where python
where conda
Next, you can add Python and Conda to your path by using the setx command in your command prompt (replace C:\Users\mgalarnyk\Anaconda2 with the results you got when running where python and where conda).
If you have a newer version of the Anaconda Navigator, open the Anaconda Prompt program that came in the install. Type all the usual conda update/conda install commands there.
I think the answers above explain this, but I could have used a very simple instruction like this. Perhaps it will help others.
In addition to adding C:\Users\yourusername\Anaconda3 and C:\Users\yourusername\Anaconda3\Scripts, as recommended by Raja (above), also add C:\Users\yourusername\Anaconda3\Library\bin to your path variable. This will prevent an SSL error that is bound to happen if you’re performing this on a fresh install of Anaconda.
I have Windows 10 64 bit, this worked for me,
This solution can work for both (Anaconda/MiniConda) distributions.
First of all try to uninstall anaconda/miniconda which is causing problem.
After that delete ‘.anaconda’ and ‘.conda’ folders from ‘C:\Users\’
If you have any antivirus software installed then try to exclude all the folders,subfolders inside ‘C:\ProgramData\Anaconda3\’ from
Behaviour detection.
Virus detection.
DNA scan.
Suspicious files scan.
Any other virus protection mode.
*(Note: ‘C:\ProgramData\Anaconda3’ this folder is default installation folder, you can change it just replace your excluded path at installation destination prompt while installing Anaconda)*
Now install Anaconda with admin privileges.
Set the installation path as ‘C:\ProgramData\Anaconda3’ or you can specify your custom path just remember it should not contain any white space and it should be excluded from virus detection.
At Advanced Installation Options you can check “Add Anaconda to my PATH environment variable(optional)” and “Register Anaconda as my default Python 3.6”
Install it with further default settings. Click on finish after done.
Restart your computer.
Now open Command prompt or Anaconda prompt and check installation using following command
conda list
If you get any package list then the anaconda/miniconda is successfully installed.
This problem arose for me when I installed Anaconda multiple times. I was careful to do an uninstall but there are some things that the uninstall process doesn’t undo.
In my case, I needed to remove a file Microsoft.PowerShell_profile.ps1 from ~\Documents\WindowsPowerShell\. I identified that this file was the culprit by opening it in a text editor. I saw that it referenced the old installation location C:\Anaconda3\.
I had this problem in windows. Most of the answers are not as recommended by anaconda, you should not add the path to the environment variables as it can break other things. Instead you should use anaconda prompt as mentioned in the top answer.
However, this may also break. In this case right click on the shortcut, go to shortcut tab, and the target value should read something like: