How can I correct my export PATH from Pipenv video?

Hello- I am new to programming and was working on the Learn Python 3 course, Modules section, Learn Python: Pipenv video. I encountered a problem when trying to change my export PATH. I’m not sure what I did incorrectly, but I am unable to access pipenv and when I open my Terminal, I get the following message:

-bash: dirname: command not found
-bash: dirname: command not found
-bash: dirname: command not found
-bash: dirname: command not found
-bash: export: =': not a valid identifier -bash: export: /Users/jeremy/.local/bin:/Users/jeremy/opt/anaconda3/bin:/bin:/condabin:/Users/jeremy/opt/anaconda3/lib/python3.7/bin:PATH’: not a valid identifier

Any help would be great! Thanks


What exactly did you type?

To check if your export is working you can try typing something like

>>> export TESTING=hello
>>> echo $TESTING
1 Like

Hi! thanks for your help- i was able to return “hello” with this command, so that worked.

I think that I initially created the issue when i input spaces before and after the ‘=’ in the export PATH command from the video instructions. But then I messed around with it, trying different paths/directories, so I’m not sure how to fix it now.

You can always edit your bash profile (check which file this is depending in your OS) and source it if you just want to export a PATH command.

Thanks- I tried editing my bash_profile (I’m not sure if I’m doing this correctly or just screwing it up more). I now get the error message:

-bash: /Users/jeremy/.bash_profile: line 16: syntax error: unexpected end of file

When I input vim ~/.bash_profile, this is what comes up:

>>> conda initialize >>>

!! Contents within this block are managed by ‘conda init’ !!

__conda_setup="('/Users/jeremy/opt/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)" if [ ? -eq 0 ]; then
eval “$__conda_setup”
if [ -f “/Users/jeremy/opt/anaconda3/etc/profile.d/” ]; then
. “/Users/jeremy/opt/anaconda3/etc/profile.d/”
export PATH="/Users/jeremy/opt/anaconda3/bin"

unset __conda_setup

<<< conda initialize <<<

export PATH="/Users/jeremy/.local/bin"
“~/.bash_profile” 15L, 524C

Did you source the file afterwards?

I’m not sure- how do i do that?

If it’s bash then source /Users/jeremy/.bash_profile is suitable (double check that file path I just copy/pasted your earlier comment).

I’m also a little confused by those export lines. Normally it’d append to your path e.g. export PATH="mynewcondapath:$PATH".

If you do mess with your conda initialisation then you can run conda init --reverse bash to remove the changes conda made to your bash profile and then conda init bash would implement those changes again.

If you are using conda I’m not sure you really need pipenv anyway. Conda has it’s own tools for managing packages and environments.

Thanks so much- I apologize for the novice questions…I am completely new to this. I am able to access the source /Users/jeremy/.bash_profile in finder and edit this file as needed.

I’m not sure about the export lines. I wish that I could just do what you said about conda…but I;'m getting “-bash: conda: command not found”

If there’s something wrong with the bash profile then then conda isn’t being added to your path so you can’t run the conda commands which would be kind of amusing if it wasn’t so annoying. Sorry about that.

I think it’s probably worthwhile removing all the lines conda has added to your .bash_profile with whatever text editor you like since something there seems to be causing problems. This would be all the text between these two lines (and those lines too)-

# >>> conda initialize >>>
# <<< conda initialize <<<

The following is an attempt to try and sort this out but only run things that you’re comfortable with-

From your message above it looks like the basic bash script for conda environment variable loading is located at the following path /Users/jeremy/opt/anaconda3/etc/profile.d/

Edit: Between these two tasks you should probably close and reopen your terminal program.

Once you’ve cleared the .bash_profile then try running
source /Users/jeremy/opt/anaconda3/etc/profile.d/ which should add conda environment variables to your current shell environment.

This should allow you to run conda commands in your current shell. Then run conda init bash to get conda to add it’s initialisation scripts to your bash_profile. You can either close and re-open your terminal and you should then be able to use conda automatically in the future (it will be sourced automatically for every new shell you open).

THANK YOU SO MUCH! I think that it’s fixed…I really appreciate it! You really helped me, this is great. Thanks again.

1 Like

Hi there!! I’m having exactly your same problem and it is very frustrating, I’m also very new with all this and I get stuck very often (but I still try).

How did you finally fix the problem?

I’m also getting the message “-bash: conda: command not found” when I try running “conda init --reverse bash”
After this step, I got confused with the last comment before you fixed it.

It’d be amazing if you can give me a hand!

You would only need to run conda init --reverse bash if you were trying to remove conda’s initialisation scripts from that file. It was necessary in this case because the section with the export statement was incorrect (at least I think that was the cause) which led to the issue of export... not a valid identifier.

A short discussion on why...

Getting conda to write to your shell initialisation scripts is a reasonable thing to do though. Unfortunately, if conda is not already added to your PATH in your shell initialisation you cannot use conda based scripts easily.

What you probably need to do is to start at the step of sourcing the backup activation script for conda so that you can use conda commands. After that running conda init bash might be helpful as it’ll add the activations hooks to your shell startup files so that new terminals will automatically have the conda commands available.

The following steps here would depend on your OS and the relevant filepaths so you’ll need to alter these commands a bit. Looking after your shell initialisation scripts in your home directory is up to you, they are designed to be personalised to suit you. As such you should know what they contain and what those commands do; you’ll save yourself some headaches if you learn even a little about them now.

I don’t know for certain as you have very little detail about what is wrong but you’d probably want to start at roughly this step:
source /Users/name/opt/anaconda3/etc/profile.d/

If that works correctly, then you can run the initialisation command to add to your shell startup scripts. If you’re on more recent OSX you’d probably be using zsh isntead of bash so adjust the command accordingly-
conda init bash

If that works you should close your open terminal and from then on any new terminals you open should have to conda commands set up automatically.

Hey! First of all, thanks for taking your time.

I tried to do what you said in your comment and this what I’m getting on my terminal.

Last login: Fri May 28 17:53:08 on ttys000
-bash: export: =': not a valid identifier -bash: export: /Users/trinidadbosch/Library/Python/3.9/bin:PATH’: not a valid identifier
MacBook-Pro-de-Trinidad:~ trinidadbosch$ source /Users/trinidadbosch/opt/anaconda3/etc/profile.d/
MacBook-Pro-de-Trinidad:~ trinidadbosch$ conda init bash
no change /Users/trinidadbosch/opt/anaconda3/condabin/conda
no change /Users/trinidadbosch/opt/anaconda3/bin/conda
no change /Users/trinidadbosch/opt/anaconda3/bin/conda-env
no change /Users/trinidadbosch/opt/anaconda3/bin/activate
no change /Users/trinidadbosch/opt/anaconda3/bin/deactivate
no change /Users/trinidadbosch/opt/anaconda3/etc/profile.d/
no change /Users/trinidadbosch/opt/anaconda3/etc/fish/conf.d/
no change /Users/trinidadbosch/opt/anaconda3/shell/condabin/Conda.psm1
no change /Users/trinidadbosch/opt/anaconda3/shell/condabin/conda-hook.ps1
no change /Users/trinidadbosch/opt/anaconda3/lib/python3.7/site-packages/xontrib/conda.xsh
no change /Users/trinidadbosch/opt/anaconda3/etc/profile.d/conda.csh
modified /Users/trinidadbosch/.bash_profile

==> For changes to take effect, close and re-open your current shell. <==

MacBook-Pro-de-Trinidad:~ trinidadbosch$

As far as I can see it says “no change” and then when I reopen my terminal the initial message still there.

Last login: Fri May 28 17:57:50 on ttys000

-bash: export: `=’: not a valid identifier

-bash: export: `/Users/trinidadbosch/Library/Python/3.9/bin:PATH’: not a valid identifier

(base) MacBook-Pro-de-Trinidad:~ trinidadbosch$

Also, when I try to source the file I’m a getting this message

MacBook-Pro-de-Trinidad:~ trinidadbosch$ /Users/trinidadbosch/.bash_profile

-bash: /Users/trinidadbosch/.bash_profile: Permission denied

What does “permission denied” means here? I’m not really sure what I’m trying to do by running it thou.

And last (cause this message is getting too long but I’m trying to give you as much detail as I can), if I run vi ~/.bash_profile, this is the message that I get (maybe I should start from here?)

export PATH = “/Users/trinidadbosch/Library/Python/3.9/bin:PATH”

Setting PATH for Python 3.8

The original version is saved in .bash_profile.pysave


export PATH

Setting PATH for Python 3.8

The original version is saved in .bash_profile.pysave


export PATH

alias python=“python3”

alias pip=“pip3”

Setting PATH for Python 3.9

The original version is saved in .bash_profile.pysave


export PATH

>>> conda initialize >>>

I’m not really sure has anything to do with conda. You seem to have a bad line in your initialisation scripts (I’m assuming one of either .bash_profile or .bashrc).

The line containing this text in particular threw the error: Users/trinidadbosch/Library/Python/3.9/bin:PATH

Can you find a line that uses that text? Do you have unusual syntax there? At a guess you’ve probably got a line that looks like-

export = '/Users/trinidadbosch/Library/Python/3.9/bin:PATH'

That should be (no spaces around the = symbol)…


I think that would be the most likely cause. Have a look and see if you can fix it.

Be aware that these two options are somewhat conflicting, if you source conda and then add yet another Python distribution to the head of you PATH you’ll probably have some trouble. I’d suggest adding only one of them at any one time, or at the very least append conda after the first one if you intend to use conda’s Python as your main Python distribution. The easiest would be one or the other though.

Ok I will, but first I tried opening again my terminal and running vi ~/.bash_profile and I’m getting this

Found a swap file by the name “~/.bash_profile.swp”
owned by: trinidadbosch dated: Fri May 28 18:43:56 2021
file name: ~trinidadbosch/.bash_profile
modified: YES
user name: trinidadbosch host name: MacBook-Pro-de-Trinidad.local
process ID: 17552
While opening file “/Users/trinidadbosch/.bash_profile”
dated: Fri May 28 18:25:40 2021

(1) Another program may be editing the same file. If this is the case,
be careful not to end up with two different instances of the same
file when making changes. Quit, or continue with caution.
(2) An edit session for this file crashed.
If this is the case, use “:recover” or “vim -r /Users/trinidadbosch/.bash_pr
to recover the changes (see “:help recovery”).
If you did this already, delete the swap file “/Users/trinidadbosch/.bash_pr
to avoid this message.

Swap file “~/.bash_profile.swp” already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:

Any idea if this is because of conda?
I prefer to do step by step and don’t mess it again!!!

I doubt it would be conda, do you have any other terminals or text editors open at this moment?
Namely this one- process ID: 17552

You might want to look into how to manage processes by id on mac if you don’t have any open editors as the most likely situation then would probably be a hung application.

Yep, found it. I pressed “D” to delete it, is that ok?

It’s unlikely to cause any significant problems, the swap file is just a history of unsaved changes that you probably made yourself. If the actual file is still there then it will still be sourced with your new log-in shells, just make sure that file is up to snuff.

It might be worth taking a little time reading into bash environment variables (including PATH) as it’s a fairly straightforward subject and it makes your life easier to see what you actually do when using these commands.

1 Like

100% agree on the reading, any recommendation of a good source?

I think it worked, after I delete it I went back and modified this code

export = ‘/Users/trinidadbosch/Library/Python/3.9/bin:PATH’

By removing the space. After I close the terminal and open it again I’m getting this

Last login: Fri May 28 19:08:18 on ttys000
-bash: dirname: command not found
-bash: dirname: command not found
-bash: dirname: command not found
-bash: dirname: command not found
(base) MacBook-Pro-de-Trinidad:~ trinidadbosch$

Any idea on what -bash: dirname: command not found means and if it is causing any troubles?