Answers.Body: <p>It is pretty weird but the only thing that I needed to do is to rename my <code>python</code> script from <code>umap.py</code> to <code>umap_gen.py</code> and right away it started to work. So, I guess there can be such name collisions which we should avoid. Although I would prefer the file to be named as <code>umap.py</code> still...</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-13T21:56:38.777Z
Answers.LastActivityDate: 2018-06-13T21:56:38.777Z
Answers.UserDisplayName: Nikita Vlasenko
Answers.Body: <p>You answered your own question, yet it is not a coincidence that you have to change the name of your script.</p>
  
  <p>When Python executes your custom script, it reads:</p>
  
  <blockquote>
    <p>import umap</p>
  </blockquote>
  
  <p>Python will first search the local sources (the directory of the script) , and afterwards the installed sources.</p>
  
  <p>In this case Python identifies the local source to be <code>umap.py</code>, and imports the (currently executed) script, while foregoing the installed sources. 
  Since you are calling functions, not defined in your current script, Python will not be able to fully execute your script.</p>
  
  <p>For more information on importing see <a href="https://docs.python.org/2/tutorial/modules.html#the-module-search-path" rel="nofollow noreferrer">Module search path</a> at docs.pyhton.org</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-14T08:02:10.787Z
Answers.LastActivityDate: 2018-06-14T10:12:01.943Z
Answers.LastEditDate: 2018-06-14T10:12:01.943Z
Answers.UserDisplayName: Kasper Thystrup Karstensen
Body: <p>Some time ago I asked the question: </p>
  
  <p><a href="https://bioinformatics.stackexchange.com/questions/4357/runumap-in-seurat-not-working-module-umap-has-no-attribute-umap">RunUMAP in Seurat not working: module &#39;umap&#39; has no attribute &#39;UMAP&#39;</a></p>
  
  <p>It was solved by following the answer in it, however, it is still not working when I run a python script from terminal, giving the same error:</p>
  
  <pre><code>python python/umap.py -path 
  "/Users/nikitavlasenko/python_scripts/output/" -data 
  "/Users/nikitavlasenko/python_scripts/data_files/WT_SCID_CCA.csv"
  </code></pre>
  
  <blockquote>
    <p>Traceback (most recent call last):
      File "python/umap.py", line 26, in 
        result = umap.UMAP().fit_transform(data.T)
    AttributeError: module 'umap' has no attribute 'UMAP'</p>
  </blockquote>
  
  <p>From inside <code>spyder</code> the same script runs perfectly, but somehow when running it from the terminal it is not successful. I am new to python, so maybe I am not pointing correctly to <code>umap</code> library? Maybe it should be imported in a different way? Here is the whole script:</p>
  
  <pre><code>import umap
  import numpy as np
  
  def getopts(argv):
  opts = {}  # Empty dictionary to store key-value pairs.
  while argv:  # While there are arguments left to parse...
      if argv[0][0] == '-':  # Found a "-name value" pair.
          opts[argv[0]] = argv[1]  # Add key and value to the dictionary.
      argv = argv[1:]  
  return opts
  
  if __name__ == '__main__':
    from sys import argv
    myargs = getopts(argv)
    print(myargs)
    path_to_save = myargs['-path']
    path_to_data = myargs['-data']
    data = np.loadtxt(open(path_to_data, "rb"), delimiter=",", skiprows=1)
    result = umap.UMAP().fit_transform(data.T)
    np.savetxt(path_to_save + "/umap.csv", result, delimiter=",")
  </code></pre>
  
  <p>Python version that is used by <code>spyder</code> and in the terminal seems to be the same: <code>3.6</code>. I am using <code>Mac OSX</code>.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-13T10:22:31.030Z
Comments.Text: Add a `print(umap.__file__)` early on. It's likely that you're getting a different copy of umap.
Comments.UserDisplayName: Devon Ryan
Tags: <python><umap>
Title: Running python script from terminal: umap issue
ThreadText: # Running python script from terminal: umap issue
  
  (Asked by: username_0 on 2018-06-12)
  
  Some time ago I asked the question:
  
  [RunUMAP in Seurat not working: module 'umap' has no attribute 'UMAP'](https://bioinformatics.stackexchange.com/questions/4357/runumap-in-seurat-not-working-module-umap-has-no-attribute-umap)
  
  It was solved by following the answer in it, however, it is still not working when I run a python script from terminal, giving the same error:
  
  ```
  python python/umap.py -path 
  "/Users/username_0/python_scripts/output/" -data 
  "/Users/username_0/python_scripts/data_files/WT_SCID_CCA.csv"
  
  ```
  
  > Traceback (most recent call last):
  > File "python/umap.py", line 26, in
  > result = umap.UMAP().fit\_transform(data.T)
  > AttributeError: module 'umap' has no attribute 'UMAP'
  
  From inside `spyder` the same script runs perfectly, but somehow when running it from the terminal it is not successful. I am new to python, so maybe I am not pointing correctly to `umap` library? Maybe it should be imported in a different way? Here is the whole script:
  
  ```
  import umap
  import numpy as np
  
  def getopts(argv):
  opts = {}  # Empty dictionary to store key-value pairs.
  while argv:  # While there are arguments left to parse...
      if argv[0][0] == '-':  # Found a "-name value" pair.
          opts[argv[0]] = argv[1]  # Add key and value to the dictionary.
      argv = argv[1:]  
  return opts
  
  if __name__ == '__main__':
    from sys import argv
    myargs = getopts(argv)
    print(myargs)
    path_to_save = myargs['-path']
    path_to_data = myargs['-data']
    data = np.loadtxt(open(path_to_data, "rb"), delimiter=",", skiprows=1)
    result = umap.UMAP().fit_transform(data.T)
    np.savetxt(path_to_save + "/umap.csv", result, delimiter=",")
  
  ```
  
  Python version that is used by `spyder` and in the terminal seems to be the same: `3.6`. I am using `Mac OSX`.
  
  **Tags:** python, umap
  
  > **Comments:**
  > **username_1**: Add a `print(umap.__file__)` early on. It's likely that you're getting a different copy of umap.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2018-06-14. Score: 5 | Accepted answer
  
  You answered your own question, yet it is not a coincidence that you have to change the name of your script.
  
  When Python executes your custom script, it reads:
  
  > import umap
  
  Python will first search the local sources (the directory of the script) , and afterwards the installed sources.
  
  In this case Python identifies the local source to be `umap.py`, and imports the (currently executed) script, while foregoing the installed sources.
  Since you are calling functions, not defined in your current script, Python will not be able to fully execute your script.
  
  For more information on importing see [Module search path](https://docs.python.org/2/tutorial/modules.html#the-module-search-path) at docs.pyhton.org
  
  
  ---
  
  ### Answer by username_0 on 2018-06-13. Score: 0
  
  It is pretty weird but the only thing that I needed to do is to rename my `python` script from `umap.py` to `umap_gen.py` and right away it started to work. So, I guess there can be such name collisions which we should avoid. Although I would prefer the file to be named as `umap.py` still...
  
  
  ---
  
  